1 #include <PartSet_Module.h>
2 #include <PartSet_OperationSketch.h>
3 #include <PartSet_OperationFeatureCreate.h>
4 #include <PartSet_OperationFeatureEditMulti.h>
5 #include <PartSet_OperationFeatureEdit.h>
6 #include <PartSet_Listener.h>
7 #include <PartSet_TestOCC.h>
8 #include <PartSet_WidgetSketchLabel.h>
9 #include <PartSet_Validators.h>
10 #include <PartSet_Tools.h>
12 #include <ModuleBase_Operation.h>
13 #include <ModuleBase_OperationDescription.h>
14 #include <ModuleBase_WidgetFactory.h>
15 #include <ModuleBase_Operation.h>
17 #include <ModelAPI_Object.h>
18 #include <ModelAPI_Events.h>
19 #include <ModelAPI_Validator.h>
20 #include <ModelAPI_Data.h>
22 #include <GeomDataAPI_Point2D.h>
24 #include <XGUI_MainWindow.h>
25 #include <XGUI_Displayer.h>
26 #include <XGUI_Viewer.h>
27 #include <XGUI_Workshop.h>
28 #include <XGUI_OperationMgr.h>
29 #include <XGUI_SelectionMgr.h>
30 #include <XGUI_Selection.h>
31 #include <XGUI_ViewPort.h>
32 #include <XGUI_ActionsMgr.h>
33 #include <XGUI_ViewerProxy.h>
34 #include <XGUI_ContextMenuMgr.h>
35 #include <XGUI_PropertyPanel.h>
36 #include <XGUI_ModuleConnector.h>
37 #include <XGUI_Tools.h>
39 #include <SketchPlugin_Line.h>
41 #include <Config_PointerMessage.h>
42 #include <Config_ModuleReader.h>
43 #include <Config_WidgetReader.h>
44 #include <Events_Loop.h>
45 #include <Events_Message.h>
46 #include <Events_Error.h>
48 #include <GeomAPI_Shape.h>
49 #include <GeomAPI_AISObject.h>
50 #include <AIS_Shape.hxx>
52 #include <StdSelect_FaceFilter.hxx>
53 #include <StdSelect_TypeOfFace.hxx>
56 #include <QMouseEvent>
59 #include <GeomAlgoAPI_FaceBuilder.h>
60 #include <GeomDataAPI_Dir.h>
66 /*!Create and return new instance of XGUI_Module*/
67 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(XGUI_Workshop* theWshop)
69 return new PartSet_Module(theWshop);
72 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
74 myWorkshop = theWshop;
75 myListener = new PartSet_Listener(this);
77 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
79 connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
81 connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
82 SLOT(onOperationStopped(ModuleBase_Operation*)));
84 XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr();
85 connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
86 SLOT(onContextMenuCommand(const QString&, bool)));
88 connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
89 SLOT(onMousePressed(QMouseEvent*)));
90 connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
91 SLOT(onMouseReleased(QMouseEvent*)));
92 connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
93 SLOT(onMouseMoved(QMouseEvent*)));
94 connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
95 SLOT(onKeyRelease(QKeyEvent*)));
96 connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
97 SLOT(onMouseDoubleClick(QMouseEvent*)));
100 PartSet_Module::~PartSet_Module()
104 XGUI_Workshop* PartSet_Module::workshop() const
109 void PartSet_Module::createFeatures()
111 //Registering of validators
112 SessionPtr aMgr = ModelAPI_Session::get();
113 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
114 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
115 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
116 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
117 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
118 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
120 Config_ModuleReader aXMLReader = Config_ModuleReader();
121 aXMLReader.readAll();
122 myFeaturesInFiles = aXMLReader.featuresInFiles();
125 void PartSet_Module::featureCreated(QAction* theFeature)
127 connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
130 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
132 return myFeaturesInFiles[theFeatureId];
138 void PartSet_Module::onFeatureTriggered()
140 //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(),
141 // myWorkshop->viewer()->activeView());
143 //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(),
144 // myWorkshop->viewer()->activeView());
145 QAction* aCmd = dynamic_cast<QAction*>(sender());
146 //Do nothing on uncheck
147 if (aCmd->isCheckable() && !aCmd->isChecked())
149 launchOperation(aCmd->data().toString());
152 void PartSet_Module::launchOperation(const QString& theCmdId)
154 ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
155 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
157 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
158 // Initialise operation with preliminary selection
159 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
160 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
161 aPreviewOp->initSelection(aSelected, aHighlighted);
163 sendOperation(anOperation);
166 void PartSet_Module::onOperationStarted()
168 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
169 ->operationMgr()->currentOperation());
171 XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
172 connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
173 SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
177 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
181 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
183 XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
184 //disconnect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)),
185 // this, SLOT(onStorePoint2D(ObjectPtr, const std::string&)));
187 // Activate results of current feature for selection
188 FeaturePtr aFeature = theOperation->feature();
189 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
190 std::list<ResultPtr> aResults = aFeature->results();
191 std::list<ResultPtr>::const_iterator aIt;
192 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
193 aDisplayer->activate(*aIt);
198 void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
200 QList<ObjectPtr> aFeatures = myWorkshop->selector()->selection()->selectedObjects();
201 if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
202 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
204 editFeature(aFeature);
208 void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
210 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
211 ->operationMgr()->currentOperation());
212 Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
213 if (aPreviewOp && (!aView.IsNull())) {
214 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
215 // Initialise operation with preliminary selection
216 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
217 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
219 aPreviewOp->mousePressed(theEvent, aView, aSelected, aHighlighted);
223 void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
225 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
226 ->operationMgr()->currentOperation());
227 Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
228 if (aPreviewOp && (!aView.IsNull())) {
229 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
230 // Initialise operation with preliminary selection
231 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
232 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
234 aPreviewOp->mouseReleased(theEvent, aView, aSelected, aHighlighted);
238 void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
240 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
241 ->operationMgr()->currentOperation());
242 Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
243 if (aPreviewOp && (!aView.IsNull()))
244 aPreviewOp->mouseMoved(theEvent, aView);
247 void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
249 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
250 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
252 aPreviewOp->keyReleased(theEvent->key());
256 void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
258 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
259 ->operationMgr()->currentOperation());
260 Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
261 if (aPreviewOp && (!aView.IsNull())) {
262 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
263 // Initialise operation with preliminary selection
264 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
265 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
266 aPreviewOp->mouseDoubleClick(theEvent, aView, aSelected, aHighlighted);
270 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
273 myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
274 myWorkshop->actionsMgr()->update();
276 //PartSet_TestOCC::testSelection(myWorkshop);
279 void PartSet_Module::onFitAllView()
281 myWorkshop->viewer()->fitAll();
284 void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject)
286 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
288 std::string aKind = aFeature ? aFeature->getKind() : "";
289 ModuleBase_Operation* anOperation = createOperation(theName, aKind);
290 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
292 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
293 // Initialise operation with preliminary selection
294 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
295 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
296 aPreviewOp->initFeature(aFeature);
297 aPreviewOp->initSelection(aSelected, aHighlighted);
298 } else if (aFeature) {
299 anOperation->setEditingFeature(aFeature);
300 //Deactivate result of current feature in order to avoid its selection
301 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
302 std::list<ResultPtr> aResults = aFeature->results();
303 std::list<ResultPtr>::const_iterator aIt;
304 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
305 aDisplayer->deactivate(*aIt);
308 sendOperation(anOperation);
309 myWorkshop->actionsMgr()->updateCheckState();
312 void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
314 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
315 aViewer->enableMultiselection(theEnabled);
318 void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
320 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
322 foreach(ObjectPtr aObject, theFeatures)
324 activateFeature(aObject, false);
327 aDisplayer->stopSelection(theFeatures, isStop, false);
329 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
330 aViewer->enableSelection(!isStop);
332 aDisplayer->updateViewer();
335 void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
337 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
338 aDisplayer->setSelected(theFeatures, false);
339 aDisplayer->updateViewer();
342 void PartSet_Module::onCloseLocalContext()
344 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
345 aDisplayer->deactivateObjectsOutOfContext();
346 aDisplayer->closeLocalContexts();
349 void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
351 bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
352 ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
353 PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
355 std::list<FeaturePtr> aList = aPrevOp->subFeatures();
356 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
357 std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
358 std::list<FeaturePtr>::iterator aSFIt;
359 for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
360 std::list<ResultPtr> aResults = (*aSFIt)->results();
361 std::list<ResultPtr>::iterator aIt;
362 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
364 aDisplayer->activateInLocalContext((*aIt), aModes, false);
366 aDisplayer->erase((*aIt), false);
369 aDisplayer->erase((*aSFIt), false);
373 ModelAPI_EventCreator::get()->sendUpdated(
374 theFeature, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
375 /* bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
376 // TODO visualizePreview(theFeature, isDisplay, false);
378 ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
380 PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
382 std::list<FeaturePtr> aList = aPrevOp->subFeatures();
383 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
384 std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
386 std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
388 //TODO for (; anIt != aLast; anIt++)
389 // visualizePreview((*anIt), false, false);
390 //aDisplayer->updateViewer();
394 if (theMode == PartSet_OperationSketchBase::FM_Activation ||
395 theMode == PartSet_OperationSketchBase::FM_Deactivation)
396 activateFeature(theFeature, true);*/
399 ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
400 const std::string& theFeatureKind)
402 // create the operation
403 ModuleBase_Operation* anOperation = 0;
404 if (theCmdId == PartSet_OperationSketch::Type()) {
405 anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
407 ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
409 PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
411 aSketch = aPrevOp->sketch();
413 if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) {
414 anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
415 } else if (theCmdId == PartSet_OperationFeatureEditMulti::Type()) {
416 anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch);
417 } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) {
418 anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
423 anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
426 // set operation description and list of widgets corresponding to the feature xml definition
427 std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
429 std::string aPluginFileName = featureFile(aFeatureKind);
430 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
431 aWdgReader.readAll();
432 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
433 std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
435 //QString aXmlRepr = QString::fromStdString(aXmlCfg);
436 //ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
437 // myWorkshop->moduleConnector());
438 //QWidget* aContent = myWorkshop->propertyPanel()->contentWidget();
439 //qDeleteAll(aContent->children());
440 //aFactory.createWidget(aContent);
442 anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
443 anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
445 //anOperation->setModelWidgets(aXmlRepr.toStdString(), aFactory.getModelWidgets());
447 // connect the operation
448 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
450 connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this,
451 SLOT(onFeatureConstructed(ObjectPtr, int)));
452 connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
453 SLOT(onRestartOperation(std::string, ObjectPtr)));
454 connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
455 SLOT(onMultiSelectionEnabled(bool)));
457 connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
458 SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
459 connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
460 SLOT(onSetSelection(const QList<ObjectPtr>&)));
462 connect(aPreviewOp, SIGNAL(closeLocalContext()), this, SLOT(onCloseLocalContext()));
464 PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
466 connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
467 SLOT(onPlaneSelected(double, double, double)));
468 connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
475 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
477 static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
478 boost::shared_ptr<Config_PointerMessage> aMessage =
479 boost::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
480 aMessage->setPointer(theOperation);
481 Events_Loop::loop()->send(aMessage);
484 /*void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
485 const bool isUpdateViewer)
487 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
491 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
495 ResultPtr aResult = theFeature->firstResult();
496 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
498 boost::shared_ptr<SketchPlugin_Feature> aSPFeature =
499 boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
501 PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
502 if (aSketchOp && !aSketchOp->hasSketchPlane())
507 aDisplayer->erase(aResult, false);
510 aDisplayer->updateViewer();
513 void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer)
515 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
516 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
518 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
519 std::list<int> aModes = aPreviewOp->getSelectionModes(theFeature);
520 aDisplayer->activateInLocalContext(theFeature, aModes, isUpdateViewer);
522 // If this is a Sketcher then activate objects (planar faces) outside of context
523 PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
525 Handle(StdSelect_FaceFilter) aFilter = new StdSelect_FaceFilter(StdSelect_Plane);
526 aDisplayer->activateObjectsOutOfContext(aModes, aFilter);
531 void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
533 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
537 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
541 FeaturePtr aFeature = aPreviewOp->feature();
542 if (!aFeature || aFeature->getKind() != theCmdId)
545 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
546 // Hide result of sketch
547 std::list<ResultPtr> aResults = aFeature->results();
548 std::list<ResultPtr>::const_iterator aIt;
549 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt)
550 aDisplayer->erase(*aIt, false);
552 std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
553 std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
555 std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
556 for (; anIt != aLast; anIt++) {
557 boost::shared_ptr<SketchPlugin_Feature> aSPFeature = boost::dynamic_pointer_cast<
558 SketchPlugin_Feature>(*anIt);
561 std::list<ResultPtr> aResults = aSPFeature->results();
562 std::list<ResultPtr>::const_iterator aRIt;
563 for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
564 aDisplayer->display((*aRIt), false);
565 aDisplayer->activateInLocalContext((*aRIt), aModes, false);
567 aDisplayer->display(aSPFeature, false);
568 aDisplayer->activateInLocalContext(aSPFeature, aModes, false);
570 aDisplayer->updateViewer();
573 void PartSet_Module::editFeature(FeaturePtr theFeature)
578 // if (theFeature->getKind() == SKETCH_KIND) {
579 //FeaturePtr aFeature = theFeature;
580 //if (XGUI_Tools::isModelObject(aFeature)) {
581 // ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
582 // aFeature = aObject->featureRef();
586 onRestartOperation(theFeature->getKind(), theFeature);
587 updateCurrentPreview(theFeature->getKind());
592 void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute)
594 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
596 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
597 ->operationMgr()->currentOperation());
601 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
602 aFeature->data()->attribute(theAttribute));
604 PartSet_Tools::setConstraints(aPreviewOp->sketch(), aFeature, theAttribute, aPoint->x(),
608 /*bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const
610 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
611 XGUI_ActionsMgr* aActMgr = myWorkshop->actionsMgr();
613 ModuleBase_Operation* aOperation = aOpMgr->currentOperation();
615 return !aActMgr->isNested(theCmdId);
617 PartSet_OperationFeatureEdit* aSketchEdtOp = dynamic_cast<PartSet_OperationFeatureEdit*>(aOperation);
619 QStringList aConstraintList;
620 aConstraintList<<"SketchConstraintDistance"<<"SketchConstraintLength"
621 <<"SketchConstraintRadius"<<"SketchConstraintParallel"<<"SketchConstraintPerpendicular";
622 return aConstraintList.contains(theCmdId);
624 QStringList aList = aActMgr->nestedCommands(aOperation->id());
625 return aList.contains(theCmdId);
628 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
629 Config_WidgetAPI* theWidgetApi,
630 QList<ModuleBase_ModelWidget*>& theModelWidgets)
632 if (theType == "sketch-start-label") {
633 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, "");
634 aWgt->setOperationsMgr(myWorkshop->operationMgr());
635 theModelWidgets.append(aWgt);
636 return aWgt->getControl();