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

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *