Attempting to isolate the “AbsoluteAngleConstraint” bug.

I was talking to Dan Heeks in the IRC and he seems to think that the problem is somewhere here: http://code.google.com/p/heekscad/source/browse/trunk/src/Constraint.cpp#332
Dan submitted http://code.google.com/p/heekscad/source/detail?r=1285
It seem like he was in a hurry, and unforturnately his fix didn’t do the trick.  I’ve been pounding on this solver for a few days trying to understand how it works and it feels like the core code is rock solid.
Any I’m pretty sure there are two bugs at work here.  I think Dan Heeks targeted the area of what was wrong..  Hmm.  I took a C++ class I wonder if I can figure it out.
It using my test 2 file http://code.google.com/p/heekscad/issues/detail?id=304

Experiment #1: Failed

<HeeksCAD_Document>

<Sketch title=”Sketch” id=”1″>

<Line col=”0″ id=”1″>
<Point col=”0″ x=”-45.5″ y=”-7″ z=”0″ id=”1″/>
<Point col=”0″ x=”-45.5″ y=”17.75″ z=”0″ id=”2″/>
</Line>

<Line col=”0″ id=”2″>
<Point col=”0″ x=”-45.5″ y=”17.75″ z=”0″ id=”3″/>
<Point col=”0″ x=”-14.5″ y=”17.75″ z=”0″ id=”4″/>
</Line>

<Line col=”0″ id=”3″>
<Point col=”0″ x=”-14.5″ y=”17.75″ z=”0″ id=”5″/>
<Point col=”0″ x=”-14.5″ y=”-7″ z=”0″ id=”6″/>
</Line>

<Line col=”0″ id=”4″>
<Point col=”0″ x=”-14.5″ y=”-7″ z=”0″ id=”7″/>
<Point col=”0″ x=”-45.5″ y=”-7″ z=”0″ id=”8″/>
</Line>
</Sketch>
<Constraint type=”CoincidantPointConstraint” angle=”AbsoluteAngleHorizontal” length=”0″ obj1_id=”8″ obj1_type=”2″ obj2_id=”1″ obj2_type=”2″ id=”4″/>
<Constraint type=”CoincidantPointConstraint” angle=”AbsoluteAngleHorizontal” length=”0″ obj1_id=”2″ obj1_type=”2″ obj2_id=”3″ obj2_type=”2″ id=”1″/>
<Constraint type=”AbsoluteAngleConstraint” angle=”AbsoluteAngleVertical” length=”0″ obj1_id=”1″ obj1_type=”3″ id=”5″/>
<Constraint type=”CoincidantPointConstraint” angle=”AbsoluteAngleHorizontal” length=”0″ obj1_id=”4″ obj1_type=”2″ obj2_id=”5″ obj2_type=”2″ id=”2″/>
<Constraint type=”AbsoluteAngleConstraint” angle=”AbsoluteAngleHorizontal” length=”0″ obj1_id=”2″ obj1_type=”3″ id=”6″/>
<Constraint type=”CoincidantPointConstraint” angle=”AbsoluteAngleHorizontal” length=”0″ obj1_id=”6″ obj1_type=”2″ obj2_id=”7″ obj2_type=”2″ id=”3″/>
<Constraint type=”AbsoluteAngleConstraint” angle=”AbsoluteAngleVertical” length=”0″ obj1_id=”3″ obj1_type=”3″ id=”7″/>
<Constraint type=”AbsoluteAngleConstraint” angle=”AbsoluteAngleHorizontal” length=”0″ obj1_id=”4″ obj1_type=”3″ id=”8″/>

</HeeksCAD_Document>

I suspected the problem might be with the overloaded constructor firing.
I but a break point in all the constructors and I drew a line and set the vertical constraint.

This Constructor function fired:
Constraint::Constraint(EnumConstraintType type,EnumAbsoluteAngle angle, ConstrainedObject* obj)

In the source constraint.cpp, HeeksObj* Constraint::ReadFromXMLElement(TiXmlElement* pElem)
Constraint(etype,eangle,length,obj1,obj2)

Ok.. I hacked the code a bit to get the same constructor to fire with no success. Now this is a more than a little irritating.  I know that AbsoluteAngleHorizontal can me set when manually drawing. So… I think the more that I make the file read look like the manual drawing, it will sooner or later work… Right?????
I think I need to start documenting the experiments:

HeeksObj* Constraint::ReadFromXMLElement(TiXmlElement* pElem)
{
const char* type=0;
EnumConstraintType etype=(EnumConstraintType)0;
const char* angle=0;
EnumAbsoluteAngle eangle=(EnumAbsoluteAngle)0;
double length=0;
int obj1_id=0;
int obj2_id=0;
int obj1_type=0;
int obj2_type=0;
ConstrainedObject* obj1=0;
ConstrainedObject* obj2=0;
// get the attributes
std::string type_name = “”; //THIS IS A JT HACK
for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
{
std::string name(a->Name());

if(name == “type”){
type = a->Value();
type_name =a->Value();//THIS IS A JT HACK
}

else if(name == “angle”){angle = a->Value();}
else if(name == “length”){length = a->DoubleValue();}
else if(name == “obj1_id”){obj1_id = a->IntValue();}
else if(name == “obj1_type”){obj1_type = a->IntValue();}
else if(name == “obj2_id”){obj2_id = a->IntValue();}
else if(name == “obj2_type”){obj2_type = a->IntValue();}
}

//Ugh, we need to convert the strings back into types
for(unsigned i=0; i < sizeof(ConstraintTypes); i++)
{
if(strcmp(ConstraintTypes[i].c_str(),type)==0)
{
etype = (EnumConstraintType)i;
break;
}
}

for(unsigned i=0; i < sizeof(AbsoluteAngle); i++)
{
if(strcmp(AbsoluteAngle[i].c_str(),angle)==0)
{
eangle = (EnumAbsoluteAngle)i;
break;
}
}

//Get real pointers to the objects
obj1 = (ConstrainedObject*)wxGetApp().GetIDObject(obj1_type,obj1_id);
obj2 = (ConstrainedObject*)wxGetApp().GetIDObject(obj2_type,obj2_id);

// JT HACKS JST
if (type_name== “AbsoluteAngleConstraint”){
//Constraint *cAbs = new Constraint(obj1);
//if(obj1)obj1->constraints.push_back(cAbs);
obj1->SetAbsoluteAngleConstraint(eangle);
}
else
{
Constraint *c = new Constraint(etype,eangle,length,obj1,obj2);

if(obj1)obj1->constraints.push_back(c);
if(obj2)obj2->constraints.push_back(c);
}
//Don’t let the xml reader try to insert us in the tree
return NULL;

I thought for sure this would work but it didn’t ;(
I got this idea by setting the break point on all the Constraint constructors to see which one fired when I set a vertical in sketch mode when it fired by hitting ctrl-shift-F7 to step out of the function and see what triggered this.
“void ConstrainedObject::SetAbsoluteAngleConstraint(EnumAbsoluteAngle angle)”  fired ” constraints.push_back(new Constraint(AbsoluteAngleConstraint,angle,this));”
which was fired by
“class SetLineVertical:public Tool run() ” fired line_for_tool->SetAbsoluteAngleConstraint(AbsoluteAngleVertical);
which was fired by
void HeeksCADapp::on_menu_event(wxCommandEvent& event) t->Run();
which was fired by
void CGraphicsCanvas::OnMenuEvent(wxCommandEvent& event) fired wxGetApp().on_menu_event(event); (which I guess was the top event)

I guess time for experiment 2.  It looks like src/HLine.cpp is point wx opengl and opencascade converge. At this point, I don’t want to dig any deeper. This is where things get pretty heavy deeper. Maybe I can get something to work at this layer
Ok… this looks interesting
class SetLineVertical:public Tool{
public:
void Run(){
line_for_tool->SetAbsoluteAngleConstraint(AbsoluteAngleVertical);
SolveSketch((CSketch*)line_for_tool->Owner());

wxGetApp().Repaint();
}
const wxChar* GetTitle(){return _(“Toggle Vertical”);}
wxString BitmapPath(){return _T(“new”);}
const wxChar* GetToolTip(){return _(“Set this line to be vertical”);}
};

Experment#2: Failed
If wonder what will happen if I invoke sketchsolve at this point. What the heck… worth a try..
It seems that the coincident points constraints works, but my little experiment had no affect.
Oh… This sucks.

HeeksObj* Constraint::ReadFromXMLElement(TiXmlElement* pElem)
{
const char* type=0;
EnumConstraintType etype=(EnumConstraintType)0;
const char* angle=0;
EnumAbsoluteAngle eangle=(EnumAbsoluteAngle)0;
double length=0;
int obj1_id=0;
int obj2_id=0;
int obj1_type=0;
int obj2_type=0;
ConstrainedObject* obj1=0;
ConstrainedObject* obj2=0;
// get the attributes
std::string type_name = “”; //THIS IS A JT HACK
for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
{
std::string name(a->Name());

if(name == “type”){
type = a->Value();
type_name =a->Value();//THIS IS A JT HACK
}

else if(name == “angle”){angle = a->Value();}
else if(name == “length”){length = a->DoubleValue();}
else if(name == “obj1_id”){obj1_id = a->IntValue();}
else if(name == “obj1_type”){obj1_type = a->IntValue();}
else if(name == “obj2_id”){obj2_id = a->IntValue();}
else if(name == “obj2_type”){obj2_type = a->IntValue();}
}

//Ugh, we need to convert the strings back into types
for(unsigned i=0; i < sizeof(ConstraintTypes); i++)
{
if(strcmp(ConstraintTypes[i].c_str(),type)==0)
{
etype = (EnumConstraintType)i;
break;
}
}

for(unsigned i=0; i < sizeof(AbsoluteAngle); i++)
{
if(strcmp(AbsoluteAngle[i].c_str(),angle)==0)
{
eangle = (EnumAbsoluteAngle)i;
break;
}
}

//Get real pointers to the objects
obj1 = (ConstrainedObject*)wxGetApp().GetIDObject(obj1_type,obj1_id);
obj2 = (ConstrainedObject*)wxGetApp().GetIDObject(obj2_type,obj2_id);

// JT HACKS JST
if (type_name== “AbsoluteAngleConstraint”){
//Constraint *cAbs = new Constraint(obj1);
//if(obj1)obj1->constraints.push_back(cAbs);
obj1->SetAbsoluteAngleConstraint(eangle);
//line_for_tool->SetAbsoluteAngleConstraint(AbsoluteAngleVertical);
SolveSketch((CSketch*)obj1->Owner());

}
else
{
Constraint *c = new Constraint(etype,eangle,length,obj1,obj2);

if(obj1)obj1->constraints.push_back(c);
if(obj2)obj2->constraints.push_back(c);
}
//Don’t let the xml reader try to insert us in the tree
return NULL;

I need to step away from this for a while..

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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