a couple of quick screen shots of a angle box using the constraint solver

It’s everything is automatically rescaled when a line is highlighted and a point dragged.
Actually what I’m shooting for here is an upright piano. But for the moment I just need to cut these out and verify that I got the geometry correct.
The v’s and h’s stand for the contraints that are applied if you export the sketch to dxf. This should all disappear.

Posted in Uncategorized | Leave a comment

Moving forward.. Issues solved and workarounds figured out.

As you can tell on my pop-up project, I’ve been experiencing a huge amount of pain (well not really, cause it was fun) on trying to use heekcad parametric solver for my little popup card project. Apparently there was at least 2 confirmed root causes and a suspect 3’rd at play here.

  1. Non-implemented code (no biggy Jonpry did a update R1303. Thank you soooo much)
  2. Design flaws in mergecommonobjects hosing up constraints (JonPry and David Nicholl’s have discussed this amongst themselves and hopefully this will be resolved soon)
  3. Undo/Redo [?]

1) My little angle box project I think pushes the constraint solver pretty hard..   I used alot of the constraints available in heekcad but not all of them.  I guess there where a couple more that if I would have run across they would have caused me the same pain as that setfixedpoint constraint had.  Difference in the code can be viewed at revision R1303.  I think I could have figured it out, but I would have taken a while.

2) These mergecommonobject thing is driven by the needs of people using heekscnc.   Apparently at the level where this is being used, constraints are not really a primary concern so when they hosed up the works no one really noticed.   The constraint bugs introduced by mergeCommonObject are pretty insidious.  They only manifest themselves in saving and are not really noticed until you reload a file.    So you’re working on a long project and what do you do? Well, you save periodically along the way.  It can be hours, till you reload the actual file.   Basically this bug caused me to have to manually delete all the constraints, renumber the sketch and point id’s and start from scratch.  Not a big deal if your talking 3 or 4 constraints, but my anglebox project has about 108 constraints in it.  That’s about 1/2 – hour each time I had to redo the constraints from scratch, (~1/2 dozen times).
Heekscad will only improve if more people start using it and really start pounding on the code.  The only way to pound on the code is with more complex projects exploring all the nooks and crannies of what heekcad has to offer. If you have an application that causes you to loose hours out of your life, because of insidious save/load bugs only anal retentive nuts like me are going to take the time to stick with it,
Just thinking out loud here, but I wonder if Heekscad might benefit by a backup file system… Sort of a auto back up along the way. Say you could set a parameter for frequency of backup, could be time or it could be by number of keystrokes. Or for that matter if you suspect a certain section of code to be the culprit, wouldn’t it be cool to have heeks data file dumped out before and after.
For me at the moment, this mergecommonobjects is an impediment to the things I want to do. Apparently this thing is real important to the heekscnc/heekscam folks since it’s been committed/uncommitted a bunch of times.
For me at moment the path of least resistance is to go around rather that through. In other words:

/*
// where operations are pointing to the same sketch, for example, make sure that they are not duplicated sketches
for (std::list::iterator itObject = objects.begin(); itObject != objects.end(); itObject++)
{
*itObject = MergeCommonObjects( unique_set, *itObject );
}
*/

I’m more than willing to test on a developed back up file, but this thing has been a major pain for me.

3) The undo/redo engine was disabled, but has been turned back on in the latest versions. It think it’s only been in the last couple of weeks, but I can’t tell exactly where,from the titles.. It’s really not that important to me. Anyway.. This to me is more of a suspicion rather than a confirmed bug. Drag and drop is a relatively new, rather cool feature in heekscad. Unfortunately, it hasn’t been idiot proofed. Currently, you can drag a line to be the child of a point if you are not careful. To me that’s a bug.. who knows what that does to the solver and undo/redo. Is that fair to expect the solver/ undo/redo to handle a wacky condition like that… Me think not.
This is a situation where if your real real careful you can avoid this. While undo/redo is an incredible cool feature, for the moment my approach to it is:

//#define USE_UNDO_ENGINE

I was going to post a couple of pictures of the ultimate coolness of using heekcad constraints to create a parametric model of an angle box, real handy stuff for paper engineering, but I have this karma thing catching up with me. I neglected my little one yesterday and and uninterrupted pounding at the keyboard is not an option today… (rightly so….)

Posted in Uncategorized | 1 Comment

Test file regarding issue 304

This is a screen shot I got when I loaded up constraints.heeks

Posted in Uncategorized | Leave a comment

Continuing the quest for the aha moment, Tracking how a simple line gets loaded in heekscad

Ok… I’ve I’m pretty much picking up from the end of my last post. (I’m not really interested in created revisions every time I edit something so probably keep this in draft mode for a while. Especially since this has got me some what confused and is going to take me a bit to work this out.

Currently I’m trying to figure out what the heck is going on with

HeeksObj* HeeksCADapp::ReadXMLElement(TiXmlElement* pElem)
{
std::string name(pElem->Value());

std::map< std::string, HeeksObj*(*)(TiXmlElement* pElem) >::iterator FindIt = xml_read_fn_map.find( name );
HeeksObj* object = NULL;
if(FindIt != xml_read_fn_map.end())
{
object = (*(FindIt->second))(pElem);
}
else
{
object = HXml::ReadFromXMLElement(pElem);
}

return object;
}

I’m confused by the “(*)” in the map. I’m starting to get a hmm but not an aha as to  whats going on .
Time to start looking at examples and tutorials here:

http://www.yolinux.com/TUTORIALS/CppStlMultiMap.html
http://www.cplusplus.com/reference/stl/map/empty/

This tutorial is fun: http://www.dreamincode.net/forums/topic/57446-stl-maps/

Duhh err I mean aha…. I just realized what was going on in that code

std::map< std::string, HeeksObj*(*)(TiXmlElement* pElem) >::iterator FindIt = xml_read_fn_map.find( name );

What going on is were declaring an iterator to a map and actually setting to xml_read_fn_map.find( name );

xml_read_fn_map is declared and populated further upstream..

void HeeksCADapp::InitializeXMLFunctions()
{
// set up function map
if(xml_read_fn_map.size() == 0)
{
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Line”, HLine::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Arc”, HArc::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “InfiniteLine”, HILine::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Circle”, HCircle::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Point”, HPoint::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Image”, HImage::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Sketch”, CSketch::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “STEP_file”, ReadSTEPFileFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “STLSolid”, CStlSolid::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “CoordinateSystem”, CoordinateSystem::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Text”, HText::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Dimension”, HDimension::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Ellipse”, HEllipse::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Spline”, HSpline::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Group”, CGroup::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Constraint”, Constraint::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “OrientationModifier”, COrientationModifier::ReadFromXMLElement ) );
}
}

So… What I think is going on here, is when I hit this line of code

object = (*(FindIt->second))(pElem);

It fires the appropriate constructor, which creates the object, which returns the address of the heekobj.. which gets returned… Darn clever..  Time to step into this to see if what I think is going on is what is going on..  That is exactly whats going on….. Cool.  There is some nuance that I’m not quite getting, but I feel I can start marching forward…

Posted in Uncategorized | Leave a comment

Quest for the aha. Tracking how a simple line gets loaded in heekscad

I have this little project that I’m trying to do in heekscad, but there is a bug in the setpointfixedconstraint which causes heeks to crash when I tried to save.
I found the line where the crash is occurring, but why it is occuring appears to be happening much further upstream.   I lack a basic understanding of how all these objects are assembled and interact with each other.    In addition my C++ knowledge is not as strong as I would like it to be.  At work, my programming time is very limited and I don’t have the time to do the stuff I’m doing here to expand my knowledge of basic C++ stuff.

At this point, I’m backing away from the constraints and trying a more fundamental understanding as to how point,lines etc… are stored.  I feel that once I understand how a line, point are stored in memory and stored  in /retrieved from a file, figuring out  constraints will be much easier.

It seems like Heeksobj is the baseclass to the lines, points etc… in heekscad.    Now how does one articulate that which he does not understand?  I suppose I should start with the part that makes sense to me.

I’m going to fire up heekscad and draw and save a single line.  Here is what the file looks like:

I needed to show this as an image because I seems I lost the indents when I tried storing this as text. I look at this file and to me, its elegant simplicity. This makes total sense to me. Actually if I complicated things and show two lines with a coincident point constraint, this makes sense to me as well.

So… I guess the issues I don’t understand is how this file structure  is represented in the the physical memory of the heekscad application.
From the XML there appears to be a bunch of parent child relationships going on here.  There is a Sketch which is the parent of Line who in turn has a couple of kids id’d  1 & 2.

I think then there are actually to sub-issues  I need to understand:

  • How is the Hierarchical model/ Parent-Child  relationships created and stored in Heekscad
  • How are the ID’s tracked/increment/assigned

I was taking a look at the class declaration of a heeksobj and that sucker has recursion written all over it to me.

class HeeksObj{
std::list<HeeksObj*> m_owners;
std::list<HeeksObj*>::iterator m_owners_it;

So… I think either one of two things is what happening here:

  • The kid is keeping track track of the addresses of her parents. (very smart kid) It would make sense to me that this list would be populated when this child is born. I guess I need to peruse the constructor functions of a HeeksObj and see if its there… (Something tells me that that would be way too easy).
  • The parent is keeping track of their kids. (Which from the wording of the variables, I don’t think that’s whats going on)

const HeeksObj& HeeksObj::operator=(const HeeksObj &ho)
{
// don’t copy the ID or the owner
m_layer = ho.m_layer;
m_visible = ho.m_visible;
m_skip_for_undo = ho.m_skip_for_undo;

if(ho.m_preserving_id)
m_id = ho.m_id;

return *this;
}

HeeksObj::~HeeksObj()
{
std::list::iterator it;
for(it = m_owners.begin(); it!= m_owners.end(); ++it)
{
(*it)->Remove(this);
}
}

So… I think this is the constructor const HeeksObj& HeeksObj::operator=(const HeeksObj &ho)?
There’s that goofy operator keyword again that I don’t totally get.
So I think there’s a clue… It says “don’t copy the ID of the owner”
Ok… I think I need to pop into some of the variables names in the class declaration HeekObj and see if we got something that hopefully simple to understand:

class HeeksObj{
std::list m_owners;
std::list::iterator m_owners_it;
public:
bool m_skip_for_undo;
unsigned int m_id;
unsigned int m_layer;
bool m_visible;
bool m_preserving_id;

Ok… so at the point of birth, the kid has not been given a name (m_id) and doesn’t have a clue who it’s parents are (m_owners)
Now looking at destruction of a object, heekobj pushes the virtual destructor pushes oblivion further downstream which I think makes sense.

I’m thinking I need to be a fly on the wall at the point of birth of a heekobj to figure out how heekcad determines who the mom is..
I guess a breakpoint in the heekobj constructors and load up my simple test file and see what happens.
So I think the first level of call stack should tell me who mom is as the file loads.

I think I want to find the actual the points where its reading the lines and then single step from that point.

If think the magic routine I need to hang out at is:

void HeeksCADapp::OpenXMLFile(const wxChar *filepath, HeeksObj* paste_into, HeeksObj* paste_before)
{
TiXmlDocument doc(Ttc(filepath));
if (!doc.LoadFile())
{
if(doc.Error())
{
wxMessageBox(Ctt(doc.ErrorDesc()));
}
return;
}

paste_into_for_ReadSTEPFileFromXMLElement = paste_into;

TiXmlHandle hDoc(&doc);
TiXmlElement* pElem;
TiXmlNode* root = &doc;

pElem=hDoc.FirstChildElement().Element();
if (!pElem) return;
std::string name(pElem->Value());
if(name == “HeeksCAD_Document”)
{
root = pElem;
}

ObjectReferences_t unique_set;

std::list<HeeksObj*> objects;
for(pElem = root->FirstChildElement(); pElem;    pElem = pElem->NextSiblingElement())
{
HeeksObj* object = ReadXMLElement(pElem);
if(object)
{
objects.push_back(object);
}
}

#if 0
// where operations are pointing to the same sketch, for example, make sure that they are not duplicated sketches
for (std::list<HeeksObj *>::iterator itObject = objects.begin(); itObject != objects.end(); itObject++)
{
*itObject = MergeCommonObjects( unique_set, *itObject );
}
#endif

if(objects.size() > 0)
{
HeeksObj* add_to = this;
if(paste_into)add_to = paste_into;
for(std::list<HeeksObj*>::const_iterator It = objects.begin(); It != objects.end(); It++)
{
HeeksObj* object = *It;
object->ReloadPointers();

if(add_to->CanAdd(object) && object->CanAddTo(add_to))
{
if(object->OneOfAKind())
{
bool one_found = false;
for(HeeksObj* child = add_to->GetFirstChild(); child; child = add_to->GetNextChild())
{
if(child->GetType() == object->GetType())
{
child->CopyFrom(object);
one_found = true;
break;
}
}
if(!one_found)
{
add_to->Add(object, paste_before);
}
}
else
{
add_to->Add(object, paste_before);
}
}
}
}

CGroup::MoveSolidsToGroupsById(this);
}

Ok.. Now this little bit of code is pretty cool.

TiXmlDocument doc(Ttc(filepath));
if (!doc.LoadFile())

It reads in a XML file apparently with the parent file relationship. This was obtained from sourceforge. I found this info in the header.
www.sourceforge.net/projects/tinyxml authored by a guy named Lee Thomason www.grinninglizard.com so basically the xml gets loaded up read for injection into heeksobj.

I’m hoping that I don’t have dig into guts of tinyxml to figure out how this heekscad stuff works.
When opening my file to read from a fresh file, both “paste_into” and “paste_before” both contain NULLS.
So this should be interesting.

paste_into_for_ReadSTEPFileFromXMLElement = paste_into;

I’m pretty sure I can ignore this with what I’m up to. It’s related to solids which I’m not messing with yet..

ObjectReferences_t unique_set;

I don’t understand what’s going on with ObjectReferences_t but I have a feeling that at some point I will since it seems that unique_set seems to be used in MergeCommonObjects (which I think has been causing me pain.)

Ok… Here’s a couple of thing we need to look at

void HeeksCADapp::OpenXMLFile(const wxChar *filepath, HeeksObj* paste_into, HeeksObj* paste_before)
{
TiXmlDocument doc(Ttc(filepath));
if (!doc.LoadFile())
{
if(doc.Error())
{
wxMessageBox(Ctt(doc.ErrorDesc()));
}
return;
}

paste_into_for_ReadSTEPFileFromXMLElement = paste_into;

TiXmlHandle hDoc(&doc);
TiXmlElement* pElem;
TiXmlNode* root = &doc;

pElem=hDoc.FirstChildElement().Element();
if (!pElem) return;
std::string name(pElem->Value());
if(name == “HeeksCAD_Document”)
{
root = pElem;
}

ObjectReferences_t unique_set;

std::list<HeeksObj*> objects;
for(pElem = root->FirstChildElement(); pElem;    pElem = pElem->NextSiblingElement())
{
HeeksObj* object = ReadXMLElement(pElem);
if(object)
{
objects.push_back(object);
}
}

#if 0
// where operations are pointing to the same sketch, for example, make sure that they are not duplicated sketches
for (std::list<HeeksObj *>::iterator itObject = objects.begin(); itObject != objects.end(); itObject++)
{
*itObject = MergeCommonObjects( unique_set, *itObject );
}
#endif

if(objects.size() > 0)
{
HeeksObj* add_to = this;
if(paste_into)add_to = paste_into;
for(std::list<HeeksObj*>::const_iterator It = objects.begin(); It != objects.end(); It++)
{
HeeksObj* object = *It;
object->ReloadPointers();

if(add_to->CanAdd(object) && object->CanAddTo(add_to))
{
if(object->OneOfAKind())
{
bool one_found = false;
for(HeeksObj* child = add_to->GetFirstChild(); child; child = add_to->GetNextChild())
{
if(child->GetType() == object->GetType())
{
child->CopyFrom(object);
one_found = true;
break;
}
}
if(!one_found)
{
add_to->Add(object, paste_before);
}
}
else
{
add_to->Add(object, paste_before);
}
}
}
}

CGroup::MoveSolidsToGroupsById(this);
}

Which goes into this.

HeeksObj* HeeksCADapp::ReadXMLElement(TiXmlElement* pElem)
{
std::string name(pElem->Value());

std::map< std::string, HeeksObj*(*)(TiXmlElement* pElem) >::iterator FindIt = xml_read_fn_map.find( name );
HeeksObj* object = NULL;
if(FindIt != xml_read_fn_map.end())
{
object = (*(FindIt->second))(pElem);
}
else
{
object = HXml::ReadFromXMLElement(pElem);
}

return object;
}

This is interesting… on the initial pass name = “sketch”
I’m a little fuzzy on whats going on with
std::map< std::string, HeeksObj*(*)(TiXmlElement* pElem) >::iterator FindIt = xml_read_fn_map.find( name );

A little research is in order http://www.cplusplus.com/reference/stl/map/
and http://en.wikipedia.org/wiki/Map_%28C%2B%2B%29

I haven’t played with map yet and it’s getting a little late… I think this is not going to sink in tonight….

When I followed object = (*(FindIt->second))(pElem); I ran in name =”line” about six or so layers down… well it late and I’m tired so I’m packing it in.

Posted in Uncategorized | Leave a comment

will Hline give me my aha moment in exploring heekscad?

First off.. I just love my Askimet plugin….to all those developers out there… I thank you. I suppose everyone’s just trying to make a living but darn… Why don’t spammers just go away….

Time to reload the Jo..
For anyone hitting this post with any of the others I guess I should recap…
I’m trying to find/fix a bug related to setPointFixedConstraint into order to finish a pop-up card project I’m working on and at the same time expand my knowledge of Heekcad/solid modeling/C++ at the same time.

[Ok… I just need to digress for a second hear… I read my daughter Droon everynight at bedtime and in each book that keep telling you how Julie,Neal,Eric team up with Galen,Princess Keah and Max the spider troll to battle against the evil Lord Sparr. (which there is a sparr on the cam# irc, who I don’t think is evil).. The author recaps this in every frikin book and this is so… irritating. ) Sorry just had to get that off my chest. I guess I’m having a internal debate with myself on whether I should do a minor recap in my blog posts. I don’t think anyone reading my dribble on a regular basis… )

I guess I’m blogging more a way for me to keep notes and not really for anyone to read. This actually comes in quite handy when I’ve need to figure out how to do something again.. Occasionally some soul has had the same issue I’ve had, and I’ve saved them a few steps…] Ok.. I’m back..

The issue that I’m having with this heeksCad stuff if that is a heck of a lot of stuff going on here.
A while back, I tried to understand what was going on and I just didn’t have the back ground in C++ what was going on. It was sort of like reading the letters without being able to understand the words. Since then I’ve done a lot of self study, took a engineers class and it’s getting better.. Heekscad has a bunch of highlevel stuff going on in there, I wish could say I understand it all, but I don’t… But as I said its been a journey… I guess I wasn’t quite back but now I really am… Coffee cup is still full, time to really focus…. Really..

I started looking a this Hline.h and I think this probably is a good spot to plant my virtual but and watch whats going on with this code….
Here’s the header file.

// HLine.h
// Copyright (c) 2009, Dan Heeks
// This program is released under the BSD license. See the file COPYING for details.

#pragma once

#include “EndedObject.h”

class HLine: public EndedObject{
private:
HeeksColor color;

public:
~HLine(void);
HLine(const gp_Pnt &a, const gp_Pnt &b, const HeeksColor* col);
HLine(const HLine &line);

const HLine& operator=(const HLine &b);

// HeeksObj’s virtual functions
int GetType()const{return LineType;}
long GetMarkingMask()const{return MARKING_FILTER_LINE;}
void glCommands(bool select, bool marked, bool no_color);
void Draw(wxDC& dc);
void GetBox(CBox &box);
const wxChar* GetTypeString(void)const{return _(“Line”);}
HeeksObj *MakeACopy(void)const;
const wxBitmap &GetIcon();
void SetColor(const HeeksColor &col){color = col;}
const HeeksColor* GetColor()const{return &color;}
void GetGripperPositions(std::list *list, bool just_for_endof);
void GetProperties(std::list
*list);
bool FindNearPoint(const double* ray_start, const double* ray_direction, double *point);
bool FindPossTangentPoint(const double* ray_start, const double* ray_direction, double *point);
void GetSegments(void(*callbackfunc)(const double *p), double pixels_per_mm, bool want_start_point = true)const;
int Intersects(const HeeksObj *object, std::list< double > *rl)const;
void CopyFrom(const HeeksObj* object){operator=(*((HLine*)object));}
void WriteXML(TiXmlNode *root);
void GetTools(std::list* t_list, const wxPoint* p);

static HeeksObj* ReadFromXMLElement(TiXmlElement* pElem);
bool UsesID(){return true;}
gp_Lin GetLine()const;
bool Intersects(const gp_Pnt &pnt)const;
gp_Vec GetSegmentVector(double fraction);
void Reverse();
};

Ok… maybe I’m weird.. No correction I am… but this section of code brings alot of stuff together for me…
first off these two little lines.

HLine(const gp_Pnt &a, const gp_Pnt &b, const HeeksColor* col);
HLine(const HLine &line);

Hear we have a two constructors taking input from two very different sources.. I recognize that gp_Pnt stuff as openCascade(which handles the solid modeling stuff). Now the &line… don’t know you…. speak up now boy… where are you defined. (in code:blocks mouse select &line and right click and chose “Find declaration of”)
Hmmm
this takes me to sketchsolve/src/solve.h

class line
{
public:
line(){}
point p1;
point p2;
};

Ok… lets look at those two lines again….

HLine(const gp_Pnt &a, const gp_Pnt &b, const HeeksColor* col);
HLine(const HLine &line);

The “const” tells me we are not going to change anything to the input data… we’re creating this Hline from it.

Looking at the class declaration of line is see we inherit EndedObject. Something tells me when I navigate through that I’ll find Heeksobj as the base class.
In my journeys so far I was running into virtual functions and polymorphism and I need a little refresher here.
I ran across this guy who actually knows whats he’s doing but seems to share my warped sense of humour.
http://www.artima.com/cppsource/pure_virtual.html
Ok.. I get this directly from this source above(but I needed to indent it and bust it up a bit, cause unlike my stuff this is terse)

In C++, a function’s interface is specified by declaring the function.
Member functions are declared in the class definition.

  • A function’s implementation is specified by defining the function.

Derived classes can redefine a function,specifying an implementation particular to that derived class (and classes derived from it).

When a virtual function is called, the implementation is chosen based not on the static type of the pointer or reference, but on the type of the object being pointed to, which can vary at run time:

print(shape->area()); // Might invoke Circle::area() or Rectangle::area().

A pure virtual function is declared, but not necessarily defined, by a base class.
A class with a pure virtual function is “abstract” (as opposed to “concrete”), in that it’s not possible to create instances of that class.

A derived class must define all inherited pure virtual functions of its base classes to be concrete.

Oiii. I just got done reading that article…. My brain is aching.. It was sort of making sense what he was talking about this “vtbl”

I was doing a little more research on this: http://en.wikipedia.org/wiki/Virtual_method_table I like the cat analogy.. Anyway… quite time is over, the house has woken up and I’m being called to make blueberry pancakes..

Just looking at HLine.h I would have thought that there would have been a couple private variable names for a couple of points… Not seeing this. But I suppose if I search the implementation of the two constructor functions that should end in the same spot one should think. This not what I had expected the two points are up one level so to speak.

Now there’s something weird going on here. There appears to be a Hline.cpp and Hiline.cpp they appear to be very similar.. I think that Hiline deals with infinite lines.

So..
…..
src/Hline.h
class HLine: public EndedObject{
….
src/EndedObject.h
class EndedObject: public ConstrainedObject{
public:
HPoint* A, *B;
….
There you go… the points I was looking for I need to explore that a bit in a moment
…..
src/ContraintedObject.h
class ConstrainedObject: public ObjList{
public:
std::list constraints;
……..
interphase/ObjList.h
class ObjList : public HeeksObj
{
protected:
std::list m_objects;
std::list::iterator LoopIt;
std::list::iterator> LoopItStack;
std::vector m_index_list; // for quick performance of GetAtIndex();
bool m_index_list_valid;

void recalculate_index_list();
void copy_objects(const ObjList& objlist);
……………..
And finally
……………..
interphase/HeeksObj.h
class HeeksObj{
std::list m_owners;
std::list::iterator m_owners_it;
public:
bool m_skip_for_undo;
unsigned int m_id;
unsigned int m_layer;
bool m_visible;
bool m_preserving_id;

HeeksObj(void);
HeeksObj(const HeeksObj& ho);
…………………….
that deal with the std::list seems a bit recursive which I suppose makes sense…
…………
Now it looks like class CHeeksCADInterface calls out a bunch of HeeksObj pointer variables….
I’m not sure where that code comes into play.. CHeeksCADInterface is called out…
Then.. there is a bunch of HeeksObj variables declared in…..
……..
class HeeksCADapp : public wxApp, public ObjList
{
……..
That looks like something that would be real close to the main() function which of course you can’t find directly in a wxwidget application.
Aw heck I use to know this..
http://www.wxwidgets.org/docs/tutorials/hello.htm
Ok… that is real close to the top…
The actual top for our purposes begins at:IMPLEMENT_APP(HeeksCADapp)… Yep yep yep…

Still not having that aha moment… But I want to get back to that

src/EndedObject.h
class EndedObject: public ConstrainedObject{
public:
HPoint* A, *B;
I wanted to see  what’s in that HPoint whats going on with that:

class HPoint: public ConstrainedObject{
private:
HeeksColor color;

public:
gp_Pnt m_p;
bool m_draw_unselected;
double mx,my;

~HPoint(void);
HPoint(const gp_Pnt &p, const HeeksColor* col);
HPoint(const HPoint &p);

const HPoint& operator=(const HPoint &b);

// HeeksObj’s virtual functions
int GetType()const{return PointType;}
long GetMarkingMask()const{return MARKING_FILTER_POINT;}
void glCommands(bool select, bool marked, bool no_color);
void GetBox(CBox &box);
const wxChar* GetTypeString(void)const{return _(“Point”);}
HeeksObj *MakeACopy(void)const;
const wxBitmap &GetIcon();
void ModifyByMatrix(const double *mat);
void SetColor(const HeeksColor &col){color = col;}
const HeeksColor* GetColor()const{return &color;}
void GetGripperPositions(std::list<GripData> *list, bool just_for_endof);
void GetProperties(std::list<Property *> *list);
bool GetStartPoint(double* pos);
bool GetEndPoint(double* pos);
void CopyFrom(const HeeksObj* object){operator=(*((HPoint*)object));}
void WriteXML(TiXmlNode *root);
void LoadFromDoubles();
void LoadToDoubles();
bool IsDifferent(HeeksObj* other);
void GetTools(std::list<Tool*>* t_list, const wxPoint* p);

void Draw(wxDC& dc);

static HeeksObj* ReadFromXMLElement(TiXmlElement* pElem);

……………………
Yikess. Lot O stuff going on in there…

gp_Pnt is defined in gp_Pnt.hxx which is in /usr/include/opencascade/gp_Pnt.hxx

//! Defines a non-persistent 3D cartesian point.

class gp_Pnt {

public:
void* operator new(size_t,void* anAddress)
{
return anAddress;
}
void* operator new(size_t size)
{
return Standard::Allocate(size);
}
void operator delete(void *anAddress)
{
if (anAddress) Standard::Free((Standard_Address&)anAddress);
}

// Methods PUBLIC
//
//! Creates an indefinite point.

gp_Pnt();
//! Creates a point with a triplet of coordinates.

gp_Pnt(const gp_XYZ& Coord);

//! Creates a point with its 3 cartesian’s coordinates : Xp, Yp, Zp.

gp_Pnt(const Standard_Real Xp,const Standard_Real Yp,const Standard_Real Zp);

//! Changes the coordinate of range Index :

//! Index = 1 => X is modified

//! Index = 2 => Y is modified

//! Index = 3 => Z is modified
//! Raised if Index != {1, 2, 3}.

void SetCoord(const Standard_Integer Index,const Standard_Real Xi) ;
//! For this point, assigns the values Xp, Yp and Zp to its three coordinates.

void SetCoord(const Standard_Real Xp,const Standard_Real Yp,const Standard_Real Zp) ;
//! Assigns the given value to the X coordinate of this point.

void SetX(const Standard_Real X) ;
//! Assigns the given value to the Y coordinate of this point.

void SetY(const Standard_Real Y) ;
//! Assigns the given value to the Z coordinate of this point.

void SetZ(const Standard_Real Z) ;
//! Assigns the three coordinates of Coord to this point.

void SetXYZ(const gp_XYZ& Coord) ;

//! Returns the coordinate of corresponding to the value of Index :

//! Index = 1 => X is returned

//! Index = 2 => Y is returned

//! Index = 3 => Z is returned

//! Raises OutOfRange if Index != {1, 2, 3}.
//! Raised if Index != {1, 2, 3}.

Standard_Real Coord(const Standard_Integer Index) const;
//! For this point gives its three coordinates Xp, Yp and Zp.

void Coord(Standard_Real& Xp,Standard_Real& Yp,Standard_Real& Zp) const;
//! For this point, returns its X coordinate.

Standard_Real X() const;
//! For this point, returns its X coordinate.

Standard_Real Y() const;
//! For this point, returns its X coordinate.

Standard_Real Z() const;
//! For this point, returns its three coordinates as a number triple.

const gp_XYZ& XYZ() const;
//! For this point, returns its three coordinates as a number triple.

const gp_XYZ& Coord() const;

//! Returns the coordinates of this point.

//! Note: This syntax allows direct modification of the returned value.

gp_XYZ& ChangeCoord() ;
//! Assigns the result of the following expression to this point

//! (Alpha*this + Beta*P) / (Alpha + Beta)

void BaryCenter(const Standard_Real Alpha,const gp_Pnt& P,const Standard_Real Beta) ;
//! Comparison

//! Returns True if the distance between the two points is

//! lower or equal to LinearTolerance.

Standard_Boolean IsEqual(const gp_Pnt& Other,const Standard_Real LinearTolerance) const;
//! Computes the distance between two points.

Standard_Real Distance(const gp_Pnt& Other) const;
//! Computes the square distance between two points.

Standard_Real SquareDistance(const gp_Pnt& Other) const;

//! Performs the symmetrical transformation of a point

//! with respect to the point P which is the center of

//! the symmetry.

Standard_EXPORT void Mirror(const gp_Pnt& P) ;

//! Performs the symmetrical transformation of a point

//! with respect to an axis placement which is the axis

//! of the symmetry.

Standard_EXPORT gp_Pnt Mirrored(const gp_Pnt& P) const;

Standard_EXPORT void Mirror(const gp_Ax1& A1) ;

//! Performs the symmetrical transformation of a point

//! with respect to a plane. The axis placement A2 locates

//! the plane of the symmetry : (Location, XDirection, YDirection).

Standard_EXPORT gp_Pnt Mirrored(const gp_Ax1& A1) const;

Standard_EXPORT void Mirror(const gp_Ax2& A2) ;

//! Rotates a point. A1 is the axis of the rotation.

//! Ang is the angular value of the rotation in radians.

Standard_EXPORT gp_Pnt Mirrored(const gp_Ax2& A2) const;

void Rotate(const gp_Ax1& A1,const Standard_Real Ang) ;
//! Scales a point. S is the scaling value.

gp_Pnt Rotated(const gp_Ax1& A1,const Standard_Real Ang) const;

void Scale(const gp_Pnt& P,const Standard_Real S) ;
//! Transforms a point with the transformation T.

gp_Pnt Scaled(const gp_Pnt& P,const Standard_Real S) const;

Standard_EXPORT void Transform(const gp_Trsf& T) ;

//! Translates a point in the direction of the vector V.

//! The magnitude of the translation is the vector’s magnitude.

gp_Pnt Transformed(const gp_Trsf& T) const;

void Translate(const gp_Vec& V) ;

//! Translates a point from the point P1 to the point P2.

gp_Pnt Translated(const gp_Vec& V) const;

void Translate(const gp_Pnt& P1,const gp_Pnt& P2) ;

gp_Pnt Translated(const gp_Pnt& P1,const gp_Pnt& P2) const;
const gp_XYZ& _CSFDB_Getgp_Pntcoord() const { return coord; }

// Type management
//
Standard_EXPORT friend Handle_Standard_Type& gp_Pnt_Type_();

protected:

// Methods PROTECTED
//

// Fields PROTECTED
//

private:

// Methods PRIVATE
//

// Fields PRIVATE
//
gp_XYZ coord;

};

Hmm…

I added some breaklines in a Hline contructor  function to see what happens when I draw a line in the sketcher….
I wasn’t really expecting this result.  When I clicked on line to define the first point, this constructor fired.

HLine::HLine(const gp_Pnt &a, const gp_Pnt &b, const HeeksColor* col):EndedObject(col){
A->m_p = a;
B->m_p = b;
color = *col;
}

The call stack looks like this:

#0 ( HLine(this=0x853f4c8, a=…, b=…, col=0x849f060) (/home/jonas/HeeksCAD/src/HLine.cpp:23)
#1 0x817dab9 LineArcDrawing::calculate_item(this=0x8378c20, end=…) (/home/jonas/HeeksCAD/src/LineArcDrawing.cpp:295)
#2 0x80eedc5 Drawing::RecalculateAndRedraw(this=0x8378c20, point=…) (/home/jonas/HeeksCAD/src/Drawing.cpp:45)
#3 0x80ef35e Drawing::OnMouse(this=0x8378c20, event=…) (/home/jonas/HeeksCAD/src/Drawing.cpp:131)
#4 0x8107f70 CGraphicsCanvas::OnMouse(this=0x85d4320, event=…) (/home/jonas/HeeksCAD/src/GraphicsCanvas.cpp:319)
#5 0xb77c2a9f wxAppConsole::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&) (/usr/lib/libwx_baseu-2.8.so.0:??)
#6 0xb7861209 wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#7 0xb78622d4 wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#8 0xb78623d3 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#10 0xb7a4d40e ??() (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#11 0xb3828424 ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#12 0xb343c252 g_closure_invoke() (/usr/lib/libgobject-2.0.so.0:??)
#13 0xb345099d ??() (/usr/lib/libgobject-2.0.so.0:??)
#14 0xb3451c33 g_signal_emit_valist() (/usr/lib/libgobject-2.0.so.0:??)
#15 0xb3452256 g_signal_emit() (/usr/lib/libgobject-2.0.so.0:??)
#16 0xb3955636 ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#17 0xb3820a5d gtk_propagate_event() (/usr/lib/libgtk-x11-2.0.so.0:??)
#18 0xb3821e07 gtk_main_do_event() (/usr/lib/libgtk-x11-2.0.so.0:??)
#19 0xb36ab39a ??() (/usr/lib/libgdk-x11-2.0.so.0:??)
#20 0xb338d5e5 g_main_context_dispatch() (/lib/libglib-2.0.so.0:??)
#21 0xb33912d8 ??() (/lib/libglib-2.0.so.0:??)
#22 0xb3391817 g_main_loop_run() (/lib/libglib-2.0.so.0:??)
#23 0xb38223c9 gtk_main() (/usr/lib/libgtk-x11-2.0.so.0:??)
#24 0xb7a38708 wxEventLoop::Run() () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#25 0xb7acb4de wxAppBase::MainLoop() () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#26 0xb7acb0d1 wxAppBase::OnRun() () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#27 0x814a61c HeeksCADapp::OnRun(this=0x849ef18) (/home/jonas/HeeksCAD/src/HeeksCAD.cpp:3139)
#28 0xb77fc79a wxEntry(int&, wchar_t**) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#29 0xb77fc977 wxEntry(int&, char**) () (/usr/lib/libwx_baseu-2.8.so.0:??)

After I ctrl F7’d code:blocks to continue I the second point would follow the cursor…. Hmm… whatever is going on it’s not the constructor thats firing… when I click the mouse the other constructor fires…

HLine::HLine(const HLine &line):EndedObject(&line.color){
operator=(line);
}

I think what going on is that I’m actually starting the second line which makes sense…

#0 ( HLine(this=0x85d6528, line=…) (/home/jonas/HeeksCAD/src/HLine.cpp:19)
#1 0x8129542 HLine::MakeACopy(this=0x8549138) (/home/jonas/HeeksCAD/src/HLine.cpp:135)
#2 0x807ef7d HeeksObj::MakeACopyWithID(this=0x8549138) (/home/jonas/HeeksCAD/interface/HeeksObj.cpp:53)
#3 0x80f651d EndedObject::MakeACopyWithID(this=0x8549138) (/home/jonas/HeeksCAD/src/EndedObject.cpp:39)
#4 0x8084f42 ObjList::copy_objects(this=0x878c990, objlist=…) (/home/jonas/HeeksCAD/interface/ObjList.cpp:70)
#5 0x8085010 ObjList::operator=(this=0x878c990, objlist=…) (/home/jonas/HeeksCAD/interface/ObjList.cpp:82)
#6 0x81e1fca CSketch::operator=(this=0x878c990, c=…) (/home/jonas/HeeksCAD/src/Sketch.cpp:58)
#7 0x81e1eb6 CSketch(this=0x878c990, c=…) (/home/jonas/HeeksCAD/src/Sketch.cpp:46)
#8 0x81e2c00 CSketch::MakeACopy(this=0x8776a00) (/home/jonas/HeeksCAD/src/Sketch.cpp:433)
#9 0x807ef7d HeeksObj::MakeACopyWithID(this=0x8776a00) (/home/jonas/HeeksCAD/interface/HeeksObj.cpp:53)
#10 0x81ff5fc UndoEngine::GetModificationsRecursive(this=0x84a54a0, ret=…, newtree=0x849ef74, oldtree=0x84a4eb8) (/home/jonas/HeeksCAD/src/UndoEngine.cpp:152)
#11 0x81ff3b7 UndoEngine::GetModifications(this=0x84a54a0, ret=…, newtree=0x849ef74, oldtree=0x84a4eb8) (/home/jonas/HeeksCAD/src/UndoEngine.cpp:113)
#12 0x81ff15a UndoEngine::GetModifications(this=0x84a54a0) (/home/jonas/HeeksCAD/src/UndoEngine.cpp:58)
#13 0x81ffe45 UndoEngine::IsModified(this=0x84a54a0) (/home/jonas/HeeksCAD/src/UndoEngine.cpp:246)
#14 0x8142093 HeeksCADapp::IsModified(this=0x849ef18) (/home/jonas/HeeksCAD/src/HeeksCAD.cpp:1798)
#15 0x8160b12 OnUpdateSave(event=…) (/home/jonas/HeeksCAD/src/HeeksFrame.cpp:753)
#16 0x8162a52 CHeeksFrame::OnUpdateExternalButton(this=0x8545bc8, event=…) (/home/jonas/HeeksCAD/src/HeeksFrame.cpp:1133)
#17 0xb77c2a9f wxAppConsole::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&) (/usr/lib/libwx_baseu-2.8.so.0:??)
#18 0xb7861209 wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#19 0xb78622d4 wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#20 0xb78623d3 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#21 0xb7862369 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#22 0xb7862369 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#23 0xb7862369 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#24 0xb7862369 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#25 0xb7b54e82 wxWindowBase::TryParent(wxEvent&) () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#26 0xb7862379 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#27 0xb7b4b52d wxToolBarBase::UpdateWindowUI(long) () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#28 0xb7abf1f0 wxToolBar::OnInternalIdle() () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#29 0xb7acb415 wxAppBase::SendIdleEvents(wxWindow*, wxIdleEvent&) () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)

So… I’m getting an aha but I am Hmmm’g a bit
This “operator=(line);” got me a bit confused… I don’t understand whats going on there…
http://www.dreamincode.net/forums/topic/39051-operator-keyword/
clearing my other break points and andding one here. Lets see if I can figure it out.
#3 0x80f651d EndedObject::MakeACopyWithID(this=0x8549138) (/home/jonas/HeeksCAD/src/EndedObject.cpp:39)
Ugg…. This is about all I can handle for now… There be a hole bunch of stuff going on…..

I think what I need to do tomorrow is to load up a heek file that contains a single line to see if it makes more sense to me.   I really need to understand what goes on with defining before I attempt a constraint.

Posted in Uncategorized | Leave a comment

More explorations on the heekscad setPointFixedconstraint

Not much time before I need to go, but I thought I see if I can peel-apart this code a bit to see if I can understand whats going on.
(R1290 came out yesterday and I have downloaded it yet, but I don’t think it effects what I’m looking at).

I’m thinking this is what I need to look at

void ConstrainedObject::SetPointFixedConstraint()
{
if(RemoveExisting(NULL,FixedPointConstraint)) return;

Constraint *c = new Constraint(FixedPointConstraint,this);
constraints.push_back(c);
}

reading the code it sort of make sense.
Set a fixed point, if its already fixed remove it your done, else set it up and put it on the list.
What I’m a little fuzzy on how the guts of this works…
(I’m running out of time here.)
Lets see if we can back up here a little. I guess I’ll pick on constraints… (Nothing personal I assure you)
What did I ever do to you? Nothing constraints… Just be quiet and accept the limelight..

class ConstrainedObject: public ObjList{
public:
std::list constraints;

ConstrainedObject();
~ConstrainedObject(void);

const ConstrainedObject& operator=(const ConstrainedObject &b);

virtual void LoadToDoubles();
virtual void LoadFromDoubles();

void SetAbsoluteAngleConstraint(EnumAbsoluteAngle angle);
bool SetPerpendicularConstraint(ConstrainedObject* obj);
bool SetParallelConstraint(ConstrainedObject* obj);
bool SetEqualLengthConstraint(ConstrainedObject* obj);
bool SetColinearConstraint(ConstrainedObject* obj);
bool SetConcentricConstraint(ConstrainedObject* obj);
bool SetEqualRadiusConstraint(ConstrainedObject* obj);
void glCommands(HeeksColor color, gp_Ax1 mid_point);
bool RemoveExisting(HeeksObj* obj, EnumConstraintType type);
Constraint* GetExisting(EnumConstraintType type);
bool HasConstraints();
void ReloadPointers();
void SetCoincidentPoint(ConstrainedObject* obj, bool remove);
bool HasPointConstraint(ConstrainedObject* obj);
void SetLineLengthConstraint(double length);
void SetLineVerticalLengthConstraint(double length);
void SetLineHorizontalLengthConstraint(double length);
void SetRadiusConstraint(double radius);
void SetLineLength(double length);
void SetLineVerticalLength(double length);
void SetLineHorizontalLength(double length);
void SetRadius(double radius);
void SetTangentConstraint(ConstrainedObject* obj);
void SetPointOnLineConstraint(HPoint* obj);
void SetPointOnLineMidpointConstraint(HPoint* obj);
void SetPointOnArcConstraint(HPoint* obj);
void SetPointOnArcMidpointConstraint(HPoint* obj);
void SetPointOnCircleConstraint(HPoint* obj);
void SetPointFixedConstraint();
};

There you are little constraints so your and stl list go back and hide. So you member of the the ObjList list class… Hmm… Lets see who you like to keep company with…

class ObjList : public HeeksObj
{
protected:
std::list m_objects;
std::list::iterator LoopIt;
std::list::iterator> LoopItStack;
std::vector m_index_list; // for quick performance of GetAtIndex();
bool m_index_list_valid;

void recalculate_index_list();
void copy_objects(const ObjList& objlist);

public:
ObjList():m_index_list_valid(true){}
ObjList(const ObjList& objlist);
virtual ~ObjList(){}

const ObjList& operator=(const ObjList& objlist);

bool operator==( const ObjList & rhs ) const;
bool operator!=( const ObjList & rhs ) const { return(! (*this == rhs)); }
bool IsDifferent(HeeksObj *other) { return( *this != (*(ObjList *)other) ); }

void ClearUndoably(void);
void Clear();
void Clear(std::set &to_delete);

HeeksObj* MakeACopy(void) const;
void GetBox(CBox &box);
void glCommands(bool select, bool marked, bool no_color);
void Draw(wxDC& dc);
HeeksObj* GetFirstChild();
HeeksObj* GetNextChild();
HeeksObj* GetAtIndex(int index);
int GetNumChildren();
bool CanAdd(HeeksObj* object){return true;}
virtual bool Add(HeeksObj* object, HeeksObj* prev_object);
virtual void Add(std::list objects);
virtual void Remove(HeeksObj* object);
virtual void Remove(std::list objects);
void KillGLLists(void);
void WriteBaseXML(TiXmlElement *element);
void ReadBaseXML(TiXmlElement* element);
void ModifyByMatrix(const double *m);
void GetTriangles(void(*callbackfunc)(const double* x, const double* n), double cusp, bool just_one_average_normal = true);
void Disconnect(std::listparents);
bool IsList(){return true;}
void GetProperties(std::list *list);
void ReloadPointers();

HeeksObj *Find( const int type, const unsigned int id ); // Search for an object by type/id from this or any child objects.
/* virtual */ void SetIdPreservation(const bool flag);
};

Ok… I’m thinking that HeeksObj will be the base class (I hope my terminology is correct here).

class HeeksObj{
std::list m_owners;
std::list::iterator m_owners_it;
public:
bool m_skip_for_undo;
unsigned int m_id;
unsigned int m_layer;
bool m_visible;
bool m_preserving_id;

HeeksObj(void);
HeeksObj(const HeeksObj& ho);
virtual ~HeeksObj();

virtual const HeeksObj& operator=(const HeeksObj &ho);

// virtual functions
virtual int GetType()const{return UnknownType;}
virtual long GetMarkingMask()const{return MARKING_FILTER_UNKNOWN;}
virtual int GetIDGroupType()const{return GetType();}
virtual void glCommands(bool select, bool marked, bool no_color){};
virtual void Draw(wxDC& dc){} // for printing
virtual bool DrawAfterOthers(){return false;}
virtual void GetBox(CBox &box){}
virtual const wxChar* GetShortString(void)const{return NULL;}
virtual const wxChar* GetTypeString(void)const{return _(“Unknown”);}
const wxChar* GetShortStringOrTypeString(void)const{if(GetShortString())return GetShortString();return GetTypeString();}
virtual bool CanEditString(void)const{return false;}
virtual void OnEditString(const wxChar* str){}
virtual void KillGLLists(void){};
virtual HeeksObj *MakeACopy()const = 0;
virtual HeeksObj *MakeACopyWithID();
virtual void ReloadPointers(){}
virtual void Disconnect(std::listparents){}
virtual void CopyFrom(const HeeksObj* object){}
virtual void SetColor(const HeeksColor &col){}
virtual const HeeksColor* GetColor()const{return NULL;}
virtual void ModifyByMatrix(const double *m){} // transform the object
virtual bool GetStartPoint(double* pos){return false;}
virtual bool GetEndPoint(double* pos){return false;}
virtual bool GetCentrePoint(double* pos){return false;}
virtual bool GetMidPoint(double* pos){return false;}
virtual bool GetScaleAboutMatrix(double *m);
virtual void GetProperties(std::list *list); // use GetDialog instead of this, if you have time to code one.
virtual ObjectCanvas* GetDialog(wxWindow* parent){return NULL;} // returns a window for editing the values of this object.
virtual void GetOnEdit(bool(**callback)(HeeksObj*)){} // returns a function for doing edit with a dialog
virtual void OnApplyProperties(){}
virtual bool ValidateProperties(){return true;}
virtual const wxBitmap &GetIcon();
virtual int Intersects(const HeeksObj *object, std::list< double > *rl)const{return 0;}
virtual bool FindNearPoint(const double* ray_start, const double* ray_direction, double *point){return false;}
virtual bool FindPossTangentPoint(const double* ray_start, const double* ray_direction, double *point){return false;}
virtual void GetTools(std::list* t_list, const wxPoint* p){}
virtual void GetGripperPositionsTransformed(std::list *list, bool just_for_endof);
virtual bool Stretch(const double *p, const double* shift, void* data){return false;} // return true, if undo stretch is done with Add and Delete
virtual bool StretchTemporary(const double *p, const double* shift, void* data){Stretch(p, shift, data); return true;} // returns true, because Stretch was done. If not done, then override and return false;
virtual bool StretchTemporaryTransformed(const double *p, const double* shift, void* data);
virtual void SetClickMarkPoint(MarkedObject* marked_object, const double* ray_start, const double* ray_direction){}
virtual bool CanAdd(HeeksObj* object){return false;}
virtual bool CanAddTo(HeeksObj* owner){return true;}
virtual bool DescendForUndo(){return true;}
virtual bool GetSkipForUndo(){return m_skip_for_undo;}
virtual void SetSkipForUndo(bool val){m_skip_for_undo = val;}
virtual bool OneOfAKind(){return false;} // if true, then, instead of pasting, find the first object of the same type and copy object to it.
virtual bool Add(HeeksObj* object, HeeksObj* prev_object) {object->AddOwner(this); object->OnAdd(); return true;}
virtual bool IsDifferent(HeeksObj* other){return false;}
virtual void Remove(HeeksObj* object){object->OnRemove();}
virtual void OnAdd(){}
virtual void OnRemove();
virtual bool CanBeRemoved(){return true;}
virtual bool CanBeCopied(){return true;}
virtual HeeksObj* GetFirstChild(){return NULL;}
virtual HeeksObj* GetNextChild(){return NULL;}
virtual HeeksObj* GetAtIndex(int index){return NULL;}
virtual int GetNumChildren(){return 0;}
virtual bool AutoExpand(){return false;}
virtual void GetTriangles(void(*callbackfunc)(const double* x, const double* n), double cusp, bool just_one_average_normal = true){} // [nine doubles, three doubles], or [nine doubles, nine doubles] if just_one_average_normal = false
virtual double Area()const{return 0.0;}
virtual void GetSegments(void(*callbackfunc)(const double *p), double pixels_per_mm, bool want_start_point = true)const{};
virtual void WriteXML(TiXmlNode *root){}
virtual void WriteBaseXML(TiXmlElement *element);
virtual void ReadBaseXML(TiXmlElement* element);
void SetID(int id);
virtual unsigned int GetID(){return m_id;}
virtual bool UsesID(){return true;}
bool OnVisibleLayer();
virtual HeeksObj* Owner();
virtual std::list Owners();
virtual void SetOwner(HeeksObj*);
virtual bool HasOwner();
virtual bool HasOwner(HeeksObj* obj);
virtual void AddOwner(HeeksObj*);
virtual void AddOwners(std::list owners);
virtual void RemoveOwners();
virtual void RemoveOwner(HeeksObj*);
virtual HeeksObj* GetFirstOwner();
virtual HeeksObj* GetNextOwner();
virtual const TopoDS_Shape *GetShape() { return(NULL); }
virtual bool IsTransient(){return false;}
virtual bool IsList(){return false;}
virtual HeeksObj *Find( const int type, const unsigned int id );
virtual void SetIdPreservation(const bool flag) { m_preserving_id = flag; }
virtual void ToString(char* buf, unsigned int* rlen, unsigned int len);
protected:
virtual void GetGripperPositions(std::list *list, bool just_for_endof);
};

Ok… this is a lot to take in here… and its time to got to work.
More later.
It’s later And I’m having a little quite time here. I’m hoping for an Aha moment……………………………… Not happening……………………….
… I’m thinking perhaps constraints is a few levels too deep conceptualize at the moment. Is looks like
ConstrainedObject inherits Objlist, which contains a bunch of HeeksObj’s

In order to understand what’s going on with constraints I think I need to back things up a bit and try to understand whats going on with a HeeksObj first. I’m thinking that mentally I need to plant my stake in Hline.cpp since that handles the creation of a line which relates to what I’m trying to accomplish..
For the record..
investigate and undertand heekscad via Hline study->find setPointFixedconstraint root cause->fix bug->procede on pop-up card project. That’s the plan anyway… Time for another post

Posted in Uncategorized | Leave a comment

Explorations of the heekcad setPointFixedconstraint.

Long stressful day today, I thought I’d relax a little a do a little code exploration.  I thought I’d step through what’s going on with the setPointFixed constraint and see if I can have an aha moment as to why this silly thing wont save.  I need to unpeel some layers to try to understand the overall architecture of this software.

As far as I’m aware there are least two ways of set a setPointFixed constraint:

  • Selected a point in the menu tree and right clicking to select “Toggle Fixed”
  • Click on sketcher background, click the line, get close to the point and the right click points=>

I set a break point on src/ConstrainedObject.cpp in the  member function[?] and set it off  using the treeview.

void ConstrainedObject::SetPointFixedConstraint()
{
if(RemoveExisting(NULL,FixedPointConstraint)) return;

Constraint *c = new Constraint(FixedPointConstraint,this);
constraints.push_back(c);
}

It seems both the tree click and direct click on the sketch seem stop at this break point.
I was curious to see what initiated these calls so I shift-ctrl F7’d to where it looks like these calls originated.
When clicking on tree view things see to get going from:
src/TreeCanvas.cpp

void CTreeCanvas::OnMenuEvent(wxCommandEvent& event)
{
wxGetApp().on_menu_event(event);
}

which goes to src/HeeksCAD.cpp:

IMPLEMENT_APP(HeeksCADapp)

Which goes to app.h

static wxAppConsole *GetInstance() { return ms_appInstance

This is now into wxwigets stuff which is deeper than I care to go at this point.
sooo shift-Ctrl F7 to backout.
Getting tired here and I it’s not too late yet… So time to pack it in… Perhaps I’ll have some time in the morning to poke at this some more.

———————————————————————————————————————–

[Edit.. 9/23/10.. Got a good nights rest… Got a hour +1 to play in the before work… Let see
Ehh.  My apologises to anyone reading my dribble on my punctuation, grammar and spelling…
I backed up using the tree view, I wonder where things back up from the break point using the sketch?

void ConstrainedObject::SetPointFixedConstraint()
{
if(RemoveExisting(NULL,FixedPointConstraint)) return;

Constraint *c = new Constraint(FixedPointConstraint,this);
constraints.push_back(c);
}

Oh… Just a quick side note. I was yakking on the irc and sliptonic mentioned thingiverse to me. I never heard of that before. I poked around this site and ran across this gem: http://www.thingiverse.com/thing:4096 My no so little little one, wanted to know when the toy machine was going to be built….(no pressure here).

Back to business.

class SetPointFixed:public Tool{
public:
void Run(){
point_for_tool->SetPointFixedConstraint();
SolveSketch((CSketch*)point_for_tool->Owner());
wxGetApp().Repaint();
}
const wxChar* GetTitle(){return _(“Toggle Fixed”);}
wxString BitmapPath(){return _T(“new”);}
const wxChar* GetToolTip(){return _(“Set this point as fixed”);}
};

I just noticed that when I shift-ctrl F7 it advances to the next line.. Opps.. I wonder if there is a way to view a call stack in code::blocks? Well according to http://www.codeblocks.org/features there is…
Just got my answer:
http://ubuntuforums.org/showthread.php?t=1580315

Hmm.. This does seem to be much more efficient than what I was doing:

#0 ( SetPointFixed::Run(this=0x83785d4) (/home/jonas/HeeksCAD/src/HPoint.cpp:137)
#1 0x81426ce HeeksCADapp::on_menu_event(this=0x849ef18, event=…) (/home/jonas/HeeksCAD/src/HeeksCAD.cpp:1939)
#2 0x81082e0 CGraphicsCanvas::OnMenuEvent(this=0x8727f70, event=…) (/home/jonas/HeeksCAD/src/GraphicsCanvas.cpp:396)
#3 0xb77c2a9f wxAppConsole::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&) (/usr/lib/libwx_baseu-2.8.so.0:??)
#4 0xb7861209 wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#5 0xb78622d4 wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#6 0xb78623d3 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#7 0xb7b2b1dd wxMenuBase::SendEvent(int, int) () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#8 0xb7aaedf0 ??() (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#9 0xb3449dcc g_cclosure_marshal_VOID__VOID() (/usr/lib/libgobject-2.0.so.0:??)
#10 0xb343c252 g_closure_invoke() (/usr/lib/libgobject-2.0.so.0:??)
#11 0xb345099d ??() (/usr/lib/libgobject-2.0.so.0:??)
#12 0xb3451db4 g_signal_emit_valist() (/usr/lib/libgobject-2.0.so.0:??)
#13 0xb3452256 g_signal_emit() (/usr/lib/libgobject-2.0.so.0:??)
#14 0xb39593e5 gtk_widget_activate() (/usr/lib/libgtk-x11-2.0.so.0:??)
#15 0xb38379a0 gtk_menu_shell_activate_item() (/usr/lib/libgtk-x11-2.0.so.0:??)
#16 0xb383931f ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#17 0xb382ec64 ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#18 0xb3828424 ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#19 0xb343a8b9 ??() (/usr/lib/libgobject-2.0.so.0:??)
#20 0xb343c252 g_closure_invoke() (/usr/lib/libgobject-2.0.so.0:??)
#21 0xb34505e6 ??() (/usr/lib/libgobject-2.0.so.0:??)
#22 0xb3451c33 g_signal_emit_valist() (/usr/lib/libgobject-2.0.so.0:??)
#23 0xb3452256 g_signal_emit() (/usr/lib/libgobject-2.0.so.0:??)
#24 0xb3955636 ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#25 0xb3820a5d gtk_propagate_event() (/usr/lib/libgtk-x11-2.0.so.0:??)
#26 0xb3821e07 gtk_main_do_event() (/usr/lib/libgtk-x11-2.0.so.0:??)
#27 0xb36ab39a ??() (/usr/lib/libgdk-x11-2.0.so.0:??)
#28 0xb338d5e5 g_main_context_dispatch() (/lib/libglib-2.0.so.0:??)
#29 0xb33912d8 ??() (/lib/libglib-2.0.so.0:??)

Awe man… Time to get ready for work ;(
But first I’m going to try this with the tree view and see what happens:

#0 ( ConstrainedObject::SetPointFixedConstraint(this=0x8773db8) (/home/jonas/HeeksCAD/src/ConstrainedObject.cpp:347)
#1 0x812bcd3 SetPointFixed::Run(this=0x83785d4) (/home/jonas/HeeksCAD/src/HPoint.cpp:136)
#2 0x81426ce HeeksCADapp::on_menu_event(this=0x849ef18, event=…) (/home/jonas/HeeksCAD/src/HeeksCAD.cpp:1939)
#3 0x81fc018 CTreeCanvas::OnMenuEvent(this=0x85e4100, event=…) (/home/jonas/HeeksCAD/src/TreeCanvas.cpp:311)
#4 0xb77c2a9f wxAppConsole::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&) (/usr/lib/libwx_baseu-2.8.so.0:??)
#5 0xb7861209 wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#6 0xb78622d4 wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#7 0xb78623d3 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#8 0xb7862369 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_baseu-2.8.so.0:??)
#9 0xb7b8d8e6 wxScrollHelperEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#10 0xb7b2b1dd wxMenuBase::SendEvent(int, int) () (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#11 0xb7aaedf0 ??() (/usr/lib/libwx_gtk2u_core-2.8.so.0:??)
#12 0xb3449dcc g_cclosure_marshal_VOID__VOID() (/usr/lib/libgobject-2.0.so.0:??)
#13 0xb343c252 g_closure_invoke() (/usr/lib/libgobject-2.0.so.0:??)
#14 0xb345099d ??() (/usr/lib/libgobject-2.0.so.0:??)
#15 0xb3451db4 g_signal_emit_valist() (/usr/lib/libgobject-2.0.so.0:??)
#16 0xb3452256 g_signal_emit() (/usr/lib/libgobject-2.0.so.0:??)
#17 0xb39593e5 gtk_widget_activate() (/usr/lib/libgtk-x11-2.0.so.0:??)
#18 0xb38379a0 gtk_menu_shell_activate_item() (/usr/lib/libgtk-x11-2.0.so.0:??)
#19 0xb383931f ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#20 0xb382ec64 ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#21 0xb3828424 ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#22 0xb343a8b9 ??() (/usr/lib/libgobject-2.0.so.0:??)
#23 0xb343c252 g_closure_invoke() (/usr/lib/libgobject-2.0.so.0:??)
#24 0xb34505e6 ??() (/usr/lib/libgobject-2.0.so.0:??)
#25 0xb3451c33 g_signal_emit_valist() (/usr/lib/libgobject-2.0.so.0:??)
#26 0xb3452256 g_signal_emit() (/usr/lib/libgobject-2.0.so.0:??)
#27 0xb3955636 ??() (/usr/lib/libgtk-x11-2.0.so.0:??)
#28 0xb3820a5d gtk_propagate_event() (/usr/lib/libgtk-x11-2.0.so.0:??)
#29 0xb3821e07 gtk_main_do_event() (/usr/lib/libgtk-x11-2.0.so.0:??)

Yikess.. t2sss
I’m going to need to redo my blog… dont’ like how its displaying… ;(

Posted in Uncategorized | Leave a comment

Taking a wack at a heekscad bug.

I was hoping to go gang busters on my pop-out project, but it doesn’t look like its going to happen..
I disabled some code a few days back that seem to cure most of my constraint problems except for a fixed point constraint.
This is probably a good mental work out for me… Lets see if I can figure this out.
I fired up heekcad sketcher true to connected lines and than tried to constrain the endpoint.  Heeks crashed when I attempted to save the endpoint.

The crash occured in this section of code(I think it was reading out a null)
void: Constraint::EndSave(TiXmlNode *root) in src/constraint.cpp

Jon Pry had added this function to heekscad which help him debug the other issue which was occurring
void HeeksObj::ToString(char *str, unsigned int* rlen, unsigned int len)
{
unsigned int printed;
*rlen = 0;

printed = snprintf(str,len,”ID: 0x%X, Type: 0x%X, MarkingMask: 0x%X, IDGroup: 0x%X\n”,GetID(),GetType(),GetMarkingMask(),GetIDGroupType());
if(printed >= len)
goto abort;
*rlen += printed; len -= printed;

abort:
*rlen = 0;
}

I found some info the snprintf here http://www.cppreference.com/wiki/c/io/snprintf
So… I think this might be my rosetta stone to figure out whats going on here.
I think the crash might be do to some null values being written out to the xml…
I thought I’d try my luck and see if I could get the output in ToString which is in a c_str to display in a wxMessagebox.
It’s been a while since I mucked with this stuff. How hard can it be?
Lets see specs:http://docs.wxwidgets.org/2.8/wx_dialogfunctions.html#wxmessagebox
Appears I need to convert a character array to wxstring
http://docs.wxwidgets.org/2.8/wx_wxstring.html#wxstring
This is too much work, I think I rather just “cout” it to a terminal window.  But  hold on … Where is the terminal window in codeblocks during debugging… I vaguely remember something weird about this…

If I just run non-debugging the terminal output just works fine.
This might provide some insight. http://forums.codeblocks.org/index.php?topic=12678.0;wap2

This log is shown by going to Settings -> Compiler & Debugger -> Debugger -> Display debugger’s log…
Ok… Now it seems the thing is displaying….
It seems that the issue is that I’m getting a null when I’m expecting something else…  The problem lays further upstream… Enough fun with this tonight..
This is going to take some time..

Posted in Uncategorized | Leave a comment

Getting closer on a parametric pop-out model using Heekscad

Ok… It seems like my vertical/horizontal constraints bug seems to have gone away with the bug-fix suggestion from Jon Pry.    I disabled the cause locally in my machine, but this is just a interim fix.
There are still some critters I’m finding then I’m trying to build my model for a diagonal pop-out box.

Commenting out the 3 lines of code seems to be working well. Setting vertical and horizontal constraints are working well,
Most of the constraints that I used seem to be functioning properly. The only one that seems to be an issue is the fixed point constraint.

It appears that I can set set a fixed point constraint in heekscad, but as soon as I save it, Heeks crashes. Heekscad is a work in progress, has a huge amount of bugs/loose ends, but most of them you can work around if you know they are there.
I’m not downing the software here… It just things that I’ve noticed that need to be fixed.  There is so much cool potential here.

  • Doesn’t appear setting color on lines works.
  • It appears that constraints are solved within a single sketch. If that’s so, why can you set constraint across 2 sketches.
  • It appears that you can drag a point from one line to another. In other words one line appears to have 3 points another line 1. There is a crash on save.
  • Inch mode doesn’t seem to be working properly.
  • When in inch mode the snap grid displayed in the background is inch.

These aren’t killing me a this point.  The fixed point constraint however is causing me some pain of finishing this little part of my project…  I am getting sooo close to success here.
Hear is where I’m at so far with my project.

A couple of weird things I should mention here:
I drew a 45 degree triangle because I needed a 45 degree angle. Either I don’t understand how to set a angle constraint or this feature hasn’t been implemented but it is how I got around for now.

The thing that I can’t get around for now is this fixed point constraint. You’ll see that I have 4 horizontal lines defined. They’re in order top to bottom and they represent:
a: Height of the rectangular cube
b: Width of the rectangular cube
c: Depth of the rectangular cube
d: Length of the gluetab line

Some of these lines are cut lines other are fold lines. I was hoping to change the fold lines to – – hidden lines to represent something called a kiss cut or a least a different color but I haven’t gotten that far.
What I want to do is to put a fixed point constraint on the left side of a,b,c,d as well as the left front corner of the cube which started out as 0,0,0 but has moved around a bit as you can see.

My end game is do export this to DXF and then import it to a WPC which pazzle paper cutter I have access to.

So… I’ve been wanting to get better at C++, I guess I need to did around in the code to see if I can figure out what’s crashing heekscad when a fixed point constraint is set and the file is saved.   Anyway that’s were things are at.

Posted in Uncategorized | Leave a comment