Integrating an A arc into the freecad polyline.

I’m starting to take a look at how the freeCad code is put together.   It is pretty massive.   At first glance the naming conventions don’t have the same naming discipline, that heekscad has, but from what I’m seeing the seems to be a far greater trail of documentation bread crumbs..

I was playing around with Freecad and I was impressed by how stable the constraints seem to be with the sketcher.  Redo/Undo all seem to be working.  But…. It is irritating that you can’t turn a polyline segment into an arc (as you can in heekscad)…
Ok.. So I asked the question, http://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=10&t=2097&start=20#p16358

I guess I volunteered myself to do this.    No problem for the moment.  I like having a certain amount of coding in my life.   There are times when I’m involved with heavy coding at work, that’s the last thing I want to look at when I get home.  At moment, I seem to be uber busy at work with work work that I’ve don’t have the time to do hardly any coding ;(  So this is fun and nice way for me to unwind.

I suppose that’s enough whining, time to start to attempt some coding at least…
Ok.. Here are the goals I’m trying to accomplish.
I need to isolate the code for the polyline events:

Looking at the behaviour of heeks err freecad. (I need to stop doing that), it looks like a new line segment gets created during a mouse up event.   So what I need to figure out where that mouse up event occurs.. (how hard can that be?).
Once I figure out the polyline mouseup event occurs I need to test for a keydown event an that’s where the real fun begins.  Something tells me the wife will be working on chores before I get to that point ;(

Arrg…. the rest of the house just woke up…
I was starting to narrow in on the break points yesterday night but I didn’t note where the breakpoints where.

(Ok.. So I cooked breakfast, that’ll give me a short reprieve and a little playtime.)

I’m thinking a good place to stick a break point is on: DrawSketchHandlerLine, which is located in /free-cad/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp

Here is some reference info.

http://freecad.sourcearchive.com/documentation/0.10.3247.dfsg-2/classDrawSketchHandlerLine.html

Ok.. I guess its not called mouseup… it’s called releaseButton… So I guess it stands to reason, I need to find something called releasekey?

On a side note… I’ve never run across this XPM stuff before..Basically, map a small image using ascii characters… cool.  I digress but I just ran past this in the code.

So here the code from

virtual bool releaseButton(Base::Vector2D onSketchPos)
{
if (Mode==STATUS_End){
unsetCursor();
resetPositionText();
Gui::Command::openCommand(“Add sketch box”);
int firstCurve = getHighestCurveIndex() + 1;
// add the four line geos
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))”,
sketchgui->getObject()->getNameInDocument(),
EditCurve[0].fX,EditCurve[0].fY,EditCurve[1].fX,EditCurve[1].fY);
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))”,
sketchgui->getObject()->getNameInDocument(),
EditCurve[1].fX,EditCurve[1].fY,EditCurve[2].fX,EditCurve[2].fY);
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))”,
sketchgui->getObject()->getNameInDocument(),
EditCurve[2].fX,EditCurve[2].fY,EditCurve[3].fX,EditCurve[3].fY);
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))”,
sketchgui->getObject()->getNameInDocument(),
EditCurve[3].fX,EditCurve[3].fY,EditCurve[0].fX,EditCurve[0].fY);
// add the four coincidents to ty them together
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addConstraint(Sketcher.Constraint(‘Coincident’,%i,2,%i,1)) ”
,sketchgui->getObject()->getNameInDocument()
,firstCurve,firstCurve+1);
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addConstraint(Sketcher.Constraint(‘Coincident’,%i,2,%i,1)) ”
,sketchgui->getObject()->getNameInDocument()
,firstCurve+1,firstCurve+2);
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addConstraint(Sketcher.Constraint(‘Coincident’,%i,2,%i,1)) ”
,sketchgui->getObject()->getNameInDocument()
,firstCurve+2,firstCurve+3);
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addConstraint(Sketcher.Constraint(‘Coincident’,%i,2,%i,1)) ”
,sketchgui->getObject()->getNameInDocument()
,firstCurve+3,firstCurve);
// add the horizontal constraints
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addConstraint(Sketcher.Constraint(‘Horizontal’,%i)) ”
,sketchgui->getObject()->getNameInDocument()
,firstCurve);
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addConstraint(Sketcher.Constraint(‘Horizontal’,%i)) ”
,sketchgui->getObject()->getNameInDocument()
,firstCurve+2);
// add the vertical constraints
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addConstraint(Sketcher.Constraint(‘Vertical’,%i)) ”
,sketchgui->getObject()->getNameInDocument()
,firstCurve+1);
Gui::Command::doCommand(Gui::Command::Doc,”App.ActiveDocument.%s.addConstraint(Sketcher.Constraint(‘Vertical’,%i)) ”
,sketchgui->getObject()->getNameInDocument()
,firstCurve+3);

Gui::Command::commitCommand();
Gui::Command::updateActive();

// add auto constraints at the start of the first side
if (sugConstr1.size() > 0) {
createAutoConstraints(sugConstr1, getHighestCurveIndex() – 3 , Sketcher::start);
sugConstr1.clear();
}

// add auto constraints at the end of the second side
if (sugConstr2.size() > 0) {
createAutoConstraints(sugConstr2, getHighestCurveIndex() – 2, Sketcher::end);
sugConstr2.clear();
}

EditCurve.clear();
sketchgui->drawEdit(EditCurve);
sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider
}
return true;
}
protected:
BoxMode Mode;
std::vector<Base::Vector2D> EditCurve;
std::vector<AutoConstraint> sugConstr1, sugConstr2;
};

 

I think if I set a break point along line 342 in /home/jonas/freecad/free-cad/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp and see if I can make sense of this… (Just a side note… The code here makes it feel like I’m looking more at C# rather than C++. It seems like the class declaration an implementation are in the same file. If memory, serves me correctly will cause things to slow down when you compiling. It seems that some files are split into cpp and h but others are not. I’m curious to know what the deal is on that…

Big Hmmmm.. I thought I had the point to set the break point when you release the mouse while drawing a polyline, but that doesn’t seem to be it.. Go figure.
I’ve got breakpoints setting up all over the point..
I’m wondering if I need to hack up Cmakelists.txt somehow to create a debug libary for freeCad.

Ok… Things have gone to from bad to worse..
I cleaned the project and re-built it.
When I attempt to run, I get this error:

make[2]: Entering directory /home/jonas/freecad/free-cad'
cd /home/jonas/freecad/free-cad && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/jonas/freecad/free-cad /home/jonas/freecad/free-cad/data/examples /home/jonas/freecad/free-cad /home/jonas/freecad/free-cad/data/examples /home/jonas/freecad/free-cad/data/examples/CMakeFiles/Example_data.dir/DependInfo.cmake --color=
make[2]: Leaving directory
/home/jonas/freecad/free-cad’
/usr/bin/make -f data/examples/CMakeFiles/Example_data.dir/build.make data/examples/CMakeFiles/Example_data.dir/build
make[2]: Entering directory /home/jonas/freecad/free-cad'
make[2]: Circular data/examples/Schenkel.stp <- data/examples/Schenkel.stp dependency dropped. /usr/bin/cmake -E cmake_progress_report /home/jonas/freecad/free-cad/CMakeFiles [100%] Generating Schenkel.stp cd /home/jonas/freecad/free-cad/data/examples && /usr/bin/cmake -E copy /home/jonas/freecad/free-cad/data/examples/Schenkel.stp /home/jonas/freecad/free-cad/data/examples/Schenkel.stp Error copying file "/home/jonas/freecad/free-cad/data/examples/Schenkel.stp" to "/home/jonas/freecad/free-cad/data/examples/Schenkel.stp". make[2]: Leaving directory
/home/jonas/freecad/free-cad'
make[2]: *** [data/examples/Schenkel.stp] Error 1
make[1]: *** [data/examples/CMakeFiles/Example_data.dir/all] Error 2
make[1]: Leaving directory `/home/jonas/freecad/free-cad'
make: *** [all] Error 2
Exited with code 2.
Error while building project FreeCAD_trunk
When executing build step 'Make'

Arggg.. I'm not sure why this isn't working....I think something is hosing up because sort and destination are the same...

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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