From 9e6beb1a013a6a90aba3ebd608f7e4c5a77a92bb Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 7 Feb 2017 19:33:36 +0100 Subject: [PATCH] Sketcher: Information layer scenography update on geometry change --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 6 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 204 ++++++++++++-------- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 4 +- 3 files changed, 131 insertions(+), 83 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 8eefe3b8e..b5c669075 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -218,7 +218,7 @@ void finishDistanceConstraint(Gui::Command* cmd, Sketcher::SketchObject* sketch, sf = vp->getScaleFactor(); constr->LabelDistance = 2. * sf; - vp->draw(); // Redraw + vp->draw(false,false); // Redraw } ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); @@ -4565,7 +4565,7 @@ void CmdSketcherConstrainRadius::activated(int iMsg) Sketcher::Constraint *constr = ConStr[indexConstr + i]; constr->LabelDistance = 2. * sf; } - vp->draw(); // Redraw + vp->draw(false,false); // Redraw } commitNeeded=true; @@ -4643,7 +4643,7 @@ void CmdSketcherConstrainRadius::activated(int iMsg) Sketcher::Constraint *constr = ConStr[indexConstr + i]; constr->LabelDistance = 2. * sf; } - vp->draw(); // Redraw + vp->draw(false,false); // Redraw } ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 7a912a0dc..292ea37e4 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -122,6 +122,11 @@ #define CONSTRAINT_SEPARATOR_INDEX_SECOND_ICON 5 #define CONSTRAINT_SEPARATOR_INDEX_SECOND_CONSTRAINTID 6 +// Macros to define information layer node child positions within type +#define GEOINFO_BSPLINE_DEGREE_POS 0 +#define GEOINFO_BSPLINE_DEGREE_TEXT 3 +#define GEOINFO_BSPLINE_POLYGON 1 + using namespace SketcherGui; using namespace Sketcher; @@ -836,7 +841,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe const_cast(viewer)->setRenderType(Gui::View3DInventorViewer::Native); // a redraw is required in order to clear the rubberband - draw(true); + draw(true,false); Mode = STATUS_NONE; return true; case STATUS_SKETCH_UseHandler: @@ -1127,7 +1132,7 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor if (GeoId != Sketcher::Constraint::GeoUndef && PosId != Sketcher::none) { if (getSketchObject()->getSolvedSketch().movePoint(GeoId, PosId, vec, relative) == 0) { setPositionText(Base::Vector2d(x,y)); - draw(true); + draw(true,false); signalSolved(QString::fromLatin1("Solved in %1 sec").arg(getSketchObject()->getSolvedSketch().SolveTime)); } else { signalSolved(QString::fromLatin1("Unsolved (%1 sec)").arg(getSketchObject()->getSolvedSketch().SolveTime)); @@ -1141,7 +1146,7 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor Base::Vector3d vec(x-xInit,y-yInit,0); if (getSketchObject()->getSolvedSketch().movePoint(edit->DragCurve, Sketcher::none, vec, relative) == 0) { setPositionText(Base::Vector2d(x,y)); - draw(true); + draw(true,false); signalSolved(QString::fromLatin1("Solved in %1 sec").arg(getSketchObject()->getSolvedSketch().SolveTime)); } else { signalSolved(QString::fromLatin1("Unsolved (%1 sec)").arg(getSketchObject()->getSolvedSketch().SolveTime)); @@ -1359,7 +1364,7 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2d &toPo for (std::vector::const_iterator it=geomlist.begin(); it != geomlist.end(); ++it) if (*it) delete *it; - draw(true); + draw(true,false); } Base::Vector3d ViewProviderSketch::seekConstraintPosition(const Base::Vector3d &origPos, @@ -3167,7 +3172,7 @@ float ViewProviderSketch::getScaleFactor() } } -void ViewProviderSketch::draw(bool temp) +void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer /*=true*/) { assert(edit); @@ -3193,11 +3198,18 @@ void ViewProviderSketch::draw(bool temp) edit->CurvIdToGeoId.clear(); - // everytime we start with empty information layer - edit->infoGroup->removeAllChildren(); + // information layer + if(rebuildinformationlayer) { + // everytime we start with empty information layer + edit->infoGroup->removeAllChildren(); + } ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); int fontSize = hGrp->GetInt("EditSketcherFontSize", 17); + + int currentInfoNode = 0; + + // end information layer int GeoId = 0; @@ -3417,12 +3429,6 @@ void ViewProviderSketch::draw(bool temp) gp_Pnt end = curve->Value(last); Coords.push_back(Base::Vector3d(end.X(), end.Y(), end.Z())); - // abdullah: Poles thought as internal geometry - /*std::vector poles = spline->getPoles(); - for (std::vector::iterator it = poles.begin(); it != poles.end(); ++it) { - Points.push_back(*it); - }*/ - Index.push_back(countSegments+1); edit->CurvIdToGeoId.push_back(GeoId); Points.push_back(startp); @@ -3431,18 +3437,6 @@ void ViewProviderSketch::draw(bool temp) //---------------------------------------------------------- // geometry information layer (degree, control polygon) // polynom degree - SoSeparator *sep = new SoSeparator(); - sep->ref(); - // no caching for fluctuand data structures - sep->renderCaching = SoSeparator::OFF; - - // every information visual node gets its own material for to-be-implemented preselection and selection - SoMaterial *mat = new SoMaterial; - mat->ref(); - mat->diffuseColor = InformationColor; - - SoTranslation *translate = new SoTranslation; - std::vector poles = spline->getPoles(); Base::Vector3d midp = Base::Vector3d(0,0,0); @@ -3453,68 +3447,120 @@ void ViewProviderSketch::draw(bool temp) midp /= poles.size(); - translate->translation.setValue(midp.x,midp.y,zInfo); + if(rebuildinformationlayer) { + SoSeparator *sep = new SoSeparator(); + sep->ref(); + // no caching for fluctuand data structures + sep->renderCaching = SoSeparator::OFF; + + // every information visual node gets its own material for to-be-implemented preselection and selection + SoMaterial *mat = new SoMaterial; + mat->ref(); + mat->diffuseColor = InformationColor; - SoFont *font = new SoFont; - font->name.setValue("Helvetica"); - font->size.setValue(fontSize); + SoTranslation *translate = new SoTranslation; + + translate->translation.setValue(midp.x,midp.y,zInfo); - SoText2 *degreetext = new SoText2; - degreetext->string = SbString(spline->getDegree()); + SoFont *font = new SoFont; + font->name.setValue("Helvetica"); + font->size.setValue(fontSize); - sep->addChild(translate); - sep->addChild(mat); - sep->addChild(font); - sep->addChild(degreetext); + SoText2 *degreetext = new SoText2; + degreetext->string = SbString(spline->getDegree()); - edit->infoGroup->addChild(sep); - sep->unref(); - mat->unref(); + sep->addChild(translate); + sep->addChild(mat); + sep->addChild(font); + sep->addChild(degreetext); + + edit->infoGroup->addChild(sep); + sep->unref(); + mat->unref(); + } + else { + SoSeparator *sep = static_cast(edit->infoGroup->getChild(currentInfoNode)); + + static_cast(sep->getChild(GEOINFO_BSPLINE_DEGREE_POS))->translation.setValue(midp.x,midp.y,zInfo); + + static_cast(sep->getChild(GEOINFO_BSPLINE_DEGREE_TEXT))->string = SbString(spline->getDegree()); + } + + currentInfoNode++; // switch to next node //---------------------------------------------------------- // control polygon - sep = new SoSeparator(); - sep->ref(); - // no caching for fluctuand data structures - sep->renderCaching = SoSeparator::OFF; - - // every information visual node gets its own material for to-be-implemented preselection and selection - mat = new SoMaterial; - mat->ref(); - mat->diffuseColor = InformationColor; - - SoLineSet *lineset = new SoLineSet; - lineset->setName("InfoLineSet"); - - SoCoordinate3 *coords = new SoCoordinate3; - - if(spline->isPeriodic()) { - coords->point.setNum(poles.size()+1); + if(rebuildinformationlayer) { + SoSeparator *sep = new SoSeparator(); + sep->ref(); + // no caching for fluctuand data structures + sep->renderCaching = SoSeparator::OFF; + + // every information visual node gets its own material for to-be-implemented preselection and selection + SoMaterial *mat = new SoMaterial; + mat->ref(); + mat->diffuseColor = InformationColor; + + SoLineSet *lineset = new SoLineSet; + lineset->setName("InfoLineSet"); + + SoCoordinate3 *coords = new SoCoordinate3; + + if(spline->isPeriodic()) { + coords->point.setNum(poles.size()+1); + } + else { + coords->point.setNum(poles.size()); + } + + SbVec3f *vts = coords->point.startEditing(); + + int i=0; + for (std::vector::iterator it = poles.begin(); it != poles.end(); ++it, i++) { + vts[i].setValue((*it).x,(*it).y,zInfo); + } + + if(spline->isPeriodic()) { + vts[poles.size()].setValue(poles[0].x,poles[0].y,zInfo); + } + + coords->point.finishEditing(); + + sep->addChild(mat); + sep->addChild(coords); + sep->addChild(lineset); + + edit->infoGroup->addChild(sep); + sep->unref(); + mat->unref(); } else { - coords->point.setNum(poles.size()); - } - - SbVec3f *vts = coords->point.startEditing(); + SoSeparator *sep = static_cast(edit->infoGroup->getChild(currentInfoNode)); + + SoCoordinate3 *coords = static_cast(sep->getChild(GEOINFO_BSPLINE_POLYGON)); + + if(spline->isPeriodic()) { + coords->point.setNum(poles.size()+1); + } + else { + coords->point.setNum(poles.size()); + } + + SbVec3f *vts = coords->point.startEditing(); + + int i=0; + for (std::vector::iterator it = poles.begin(); it != poles.end(); ++it, i++) { + vts[i].setValue((*it).x,(*it).y,zInfo); + } + + if(spline->isPeriodic()) { + vts[poles.size()].setValue(poles[0].x,poles[0].y,zInfo); + } + + coords->point.finishEditing(); - int i=0; - for (std::vector::iterator it = poles.begin(); it != poles.end(); ++it, i++) { - vts[i].setValue((*it).x,(*it).y,zInfo); } - - if(spline->isPeriodic()) { - vts[poles.size()].setValue(poles[0].x,poles[0].y,zInfo); - } - - coords->point.finishEditing(); - - sep->addChild(mat); - sep->addChild(coords); - sep->addChild(lineset); - - edit->infoGroup->addChild(sep); - sep->unref(); - mat->unref(); + currentInfoNode++; // switch to next node } else { } @@ -4568,7 +4614,7 @@ void ViewProviderSketch::updateData(const App::Property *prop) getSketchObject()->getSolvedSketch().getGeometrySize()) { Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView(); if (mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) - draw(false); + draw(false,true); signalConstraintsChanged(); signalElementsChanged(); @@ -4754,7 +4800,7 @@ bool ViewProviderSketch::setEdit(int ModNum) getSketchObject()->solve(false); UpdateSolverInformation(); - draw(false); + draw(false,true); connectUndoDocument = Gui::Application::Instance->activeDocument() ->signalUndoDocument.connect(boost::bind(&ViewProviderSketch::slotUndoDocument, this, _1)); @@ -5386,7 +5432,7 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) // if the sketched could not be solved, we first redraw to update the UI geometry as // onChanged did not update it. UpdateSolverInformation(); - draw(); + draw(false,true); signalConstraintsChanged(); signalElementsChanged(); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 2da0ff91e..8e95ec4e4 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -110,7 +110,9 @@ public: void drawConstraintIcons(); /// draw the sketch in the inventor nodes - void draw(bool temp=false); + /// temp => use temporary solver solution in SketchObject + /// recreateinformationscenography => forces a rebuild of the information layer scenography + void draw(bool temp=false, bool rebuildinformationlayer=true); /// draw the edit curve void drawEdit(const std::vector &EditCurve);