Hitting a few little snags on my constraint tester.

I was moving write along..  I got my little test function to fire from the main menu and I tried to get a m_objects as a variable and got myself tripped up a bit because I was attempting to access protected data.

I found some interesting data here.
http://www.parashift.com/c++-faq-lite/basics-of-inheritance.html

Ugg… I thought I was templating from SaveXML but I must be missing something here. So protected data is visible to the object, and objects that inherit that object.

Duh… I think I”m beginning to understand…
I setup my function call like this:

#ifdef CONSTRAINT_TESTER
bool HeeksCADapp::TestForValidConstraints(const std::list<HeeksObj*>& objects)
{
wxMessageBox(_(“Hello World”));
//JT
//The idea to this routine is to search through the object list that savefile uses and see
//is everything makes sense.
//This routine at the moment is only executed manually through the main menu
//The idea is to insert this into various test points to get an idea where constraints are getting screwed up.

}
#endif

I hacked around and was getting errors here:

#ifdef FIRE_CONSTRAINT_TESTER_FROM_MAIN_MENU
static void OnTestConstraint( wxCommandEvent& event )
{

wxGetApp().TestForValidConstraints(m_objects);

}
#endif

Error:

/home/jonas/HeeksCAD/src/HeeksFrame.cpp|1114|error: ‘m_objects’ was not declared in this scope|

I was wondering earlier why they had this inline function defined:

void SaveXMLFile(const wxChar *filepath){SaveXMLFile(m_objects, filepath);}

It makes sense now my TestForValidConstraints is outside any object therefore is m_objects is protected it is not visible.
So from the context of mimicking a file save I need to do something similar here and get rid of the m_objects in my call and all should be well.

Eehh… this is embarrassingly obvious.
This is what I needed:

//JT
#ifdef CONSTRAINT_TESTER
bool TestForValidConstraints(){return TestForValidConstraints(m_objects);};//m_objects is protected and visible to class or sub_class
bool TestForValidConstraints(const std::list<HeeksObj*>& objects);

#endif

(Running into a small issue.. When I compile because I’m working in a baseclass it seems that everything recompiles and takes a lot or time. (I wonder if there is away around that or that’s just need to grin and bear it (Santa if your out that a nice quad-core would be appreciated under the tree 😉 )
Hmmm.. I saw there was an option to compile the current file in code::blocks I need to try that next. That might be the ticket.

Ok. Everything seems to be working the way I want.
Now.. To start getting a little into the bloody details.
I probably should get an understanding of how m_objects gets populated, but for the moment, I’m just going to accept that it exists.
When I start pulling up constraint errors I guess I’ll need to figure it out.

Here is the section of code that I needs to be dissected:

void HeeksCADapp::SaveXMLFile(const std::list& objects, const wxChar *filepath, bool for_clipboard)
{
// write an xml file
TiXmlDocument doc;
const char *l_pszVersion = “1.0”;
const char *l_pszEncoding = “UTF-8”;
const char *l_pszStandalone = “”;

TiXmlDeclaration* decl = new TiXmlDeclaration( l_pszVersion, l_pszEncoding, l_pszStandalone);
doc.LinkEndChild( decl );

TiXmlNode* root = &doc;
if(!for_clipboard)
{
root = new TiXmlElement( “HeeksCAD_Document” );
doc.LinkEndChild( root );
}

// loop through all the objects writing them
CShape::m_solids_found = false;
Constraint::BeginSave();
for(std::list::const_iterator It = objects.begin(); It != objects.end(); It++)
{
HeeksObj* object = *It;
object->WriteXML(root);
}

// write the constraints to the root-if check box is selected
if (m_save_constraints){
Constraint::EndSave(root);

}

I have poked around a little in this code already so I sort of know whats going on here, but I still fuzzy one a bunch of stuff.
I know constraints don’t lend themselves to parent child xml type data which is why they saved as a root.  Looking at the code it seems to me that m_objects contains parent objects which WriteXML drills down further.  I’m not sure that’s correct but I suppose that’s easy enough to test by drawing a single line in heeksCAD and single stepping in debug to see what happens.

void CSketch::WriteXML(TiXmlNode *root)
{
if (GetNumChildren() > 0)
{
TiXmlElement * element = new TiXmlElement( “Sketch” );
root->LinkEndChild( element );
element->SetAttribute(“title”, m_title.utf8_str());
WriteBaseXML(element);
}
}

Wonder what happens with GetNumChildren()

int ObjList::GetNumChildren()
{
return m_objects.size();
}

I suppose we go one deeper…
Oh… Too deep duh… the steps me into stl_list.h I think the m_objects where looking at here is not m_objects that’s inside the object (I think line) not the m_objects within HeeksCADapp (time to step out..)

The next thing that interests me is the WriteBaseXML

void ObjList::WriteBaseXML(TiXmlElement *element)
{
std::list::iterator It;
for(It=m_objects.begin(); It!=m_objects.end() ;It++) (*It)->WriteXML(element);
HeeksObj::WriteBaseXML(element);

Time to peek into WriteBaseXML:

void HeeksObj::WriteBaseXML(TiXmlElement *element)
{
#ifdef HEEKSCAD
wxGetApp().ObjectWriteBaseXML(this, element);
#else
heeksCAD->ObjectWriteBaseXML(this, element);
#endif

So this is where the ID gets written out.

void HeeksCADapp::ObjectWriteBaseXML(HeeksObj *object, TiXmlElement *element)
{
if(object->UsesID())element->SetAttribute(“id”, object->m_id);
if(!object->m_visible)element->SetAttribute(“vis”, 0);
}

Alright/… so the file I just created just looks like this:

<?xml version=”1.0″ encoding=”UTF-8″ ?>
<HeeksCAD_Document>
<Sketch title=”Sketch” id=”1″>
<Line col=”0″ id=”1″>
<Point col=”0″ x=”-21″ y=”6″ z=”0″ id=”1″ />
<Point col=”0″ x=”-2″ y=”12″ z=”0″ id=”2″ />
</Line>
</Sketch>
</HeeksCAD_Document>

So I believe that I have 3 heeksobj’s here,  I line and two children points..
Double checking here.
Yep…. Just one pass….
So… I think if I draw 2 lines connected by a coincident point constraint it should be 3 passes… I’m talking about this section of code which is in:
void HeeksCADapp::SaveXMLFile(const std::list& objects, const wxChar *filepath, bool for_clipboard)

…..
for(std::list::const_iterator It = objects.begin(); It != objects.end(); It++)
{
HeeksObj* object = *It;
object->WriteXML(root);
}
…..

Heh??? Only one pass… Darn… that would have been too easy..
I wonder if m_objects at HeeksCADapp is referring to sketches.. I suppose that’s easy enough to check out.
Create two sketches and see if we just get 2 passes: Yep that works…. but has made life much more complicated…

Ok… I need to create two sketches consisting of two lines each connected with a coincident point constraint and see how the data looks like.

<?xml version=”1.0″ encoding=”UTF-8″ ?>
<HeeksCAD_Document>
<Sketch title=”Sketch” id=”1″>
<Line col=”0″ id=”1″>
<Point col=”0″ x=”-24″ y=”12″ z=”0″ id=”1″ />
<Point col=”0″ x=”-13″ y=”21″ z=”0″ id=”2″ />
</Line>
<Line col=”0″ id=”2″>
<Point col=”0″ x=”-13″ y=”21″ z=”0″ id=”5″ />
<Point col=”0″ x=”4″ y=”16″ z=”0″ id=”6″ />
</Line>
</Sketch>
<Sketch title=”Sketch” id=”2″>
<Line col=”0″ id=”3″>
<Point col=”0″ x=”-24″ y=”-13″ z=”0″ id=”21″ />
<Point col=”0″ x=”-14″ y=”-3″ z=”0″ id=”22″ />
</Line>
<Line col=”0″ id=”4″>
<Point col=”0″ x=”-14″ y=”-3″ z=”0″ id=”25″ />
<Point col=”0″ x=”-5″ y=”-13″ z=”0″ id=”26″ />
</Line>
</Sketch>
<Constraint type=”CoincidantPointConstraint” angle=”AbsoluteAngleHorizontal” length=”0″ obj1_id=”2″ obj1_type=”2″ obj2_id=”5″ obj2_type=”2″ id=”1″ />
<Constraint type=”CoincidantPointConstraint” angle=”AbsoluteAngleHorizontal” length=”0″ obj1_id=”22″ obj1_type=”2″ obj2_id=”25″ obj2_type=”2″ id=”2″ />
</HeeksCAD_Document>

Ugg…
Getting back to:

Constraint::BeginSave(); // This clears out obj_to_save and obj_to_save_find
// This constraint list appears to be declared globally not within any object in
// src/Constraint.cpp
//static std::list obj_to_save;
//static std::set obj_to_save_find;
for(std::list::const_iterator It = objects.begin(); It != objects.end(); It++) // SaveXML when called from savefile object is passing a m_objects list
// Declared in HeeksCADapp
// m_objects apparently is a list of sketch objects
{
HeeksObj* object = *It;
object->WriteXML(root); //so here were drilling down from the sketch object
//somewhere in this process when we run across a constraint object, a pointer to it gets send to obj_to_save
//great 🙁
}

// write the constraints to the root-if check box is selected
if (m_save_constraints){
Constraint::EndSave(root);
}

Well… So much for the easy routine… I guess what I need to do is to drill down into WriteXML(root) to really understand what’s going on there.
But I think I’m going just push my little function just a bit further.

I just loaded my two sketch to line sample and fired it up this routine and got two messages to fire…
//asdf
#ifdef CONSTRAINT_TESTER
bool HeeksCADapp::TestForValidConstraints(const std::list& objects)
{

//JT
//The idea to this routine is to search through the object list that savefile uses and see
//is everything makes sense.
//This routine at the moment is only executed manually through the main menu
//The idea is to insert this into various test points to get an idea where constraints are getting screwed up.
for(std::list::const_iterator It = objects.begin(); It != objects.end(); It++)
{
HeeksObj* object = *It;
wxMessageBox(_(“Hello World from inside TestforValidConstraints”));
//object need to do something more here.
}
}
#endif

That’s enough of this for a while..
Next step is to dive into writeXML(root)..

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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