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 <ModuleBase_Operation.h>
7 #include <ModuleBase_OperationDescription.h>
8 #include <ModuleBase_WidgetFactory.h>
9 #include <PartSet_Listener.h>
10 #include <PartSet_TestOCC.h>
11 #include <PartSet_WidgetSketchLabel.h>
12 #include <PartSet_Validators.h>
14 #include <ModuleBase_Operation.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_Events.h>
17 #include <ModelAPI_Validator.h>
19 #include <ModelAPI_Data.h>
20 #include <GeomDataAPI_Point2D.h>
21 #include <PartSet_Tools.h>
23 #include <XGUI_MainWindow.h>
24 #include <XGUI_Displayer.h>
25 #include <XGUI_Viewer.h>
26 #include <XGUI_Workshop.h>
27 #include <XGUI_OperationMgr.h>
28 #include <XGUI_SelectionMgr.h>
29 #include <XGUI_Selection.h>
30 #include <XGUI_ViewPort.h>
31 #include <XGUI_ActionsMgr.h>
32 #include <XGUI_ViewerProxy.h>
33 #include <XGUI_ContextMenuMgr.h>
34 #include <XGUI_PropertyPanel.h>
35 #include <XGUI_ModuleConnector.h>
36 #include <XGUI_Tools.h>
38 #include <SketchPlugin_Line.h>
40 #include <Config_PointerMessage.h>
41 #include <Config_ModuleReader.h>
42 #include <Config_WidgetReader.h>
43 #include <Events_Loop.h>
44 #include <Events_Message.h>
45 #include <Events_Error.h>
47 #include <GeomAPI_Shape.h>
48 #include <GeomAPI_AISObject.h>
49 #include <AIS_Shape.hxx>
52 #include <QMouseEvent>
55 #include <GeomAlgoAPI_FaceBuilder.h>
56 #include <GeomDataAPI_Dir.h>
63 //const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color
64 const double SKETCH_WIDTH = 4.0; /// the plane edge width
65 // face of the square-face displayed for selection of general plane
66 const double PLANE_SIZE = 200;
69 /*!Create and return new instance of XGUI_Module*/
70 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(XGUI_Workshop* theWshop)
72 return new PartSet_Module(theWshop);
75 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
77 myWorkshop = theWshop;
78 myListener = new PartSet_Listener(this);
80 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
82 connect(anOperationMgr, SIGNAL(operationStarted()),
83 this, SLOT(onOperationStarted()));
85 connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
86 this, SLOT(onOperationStopped(ModuleBase_Operation*)));
88 XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr();
89 connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)),
90 this, SLOT(onContextMenuCommand(const QString&, bool)));
92 connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)),
93 this, SLOT(onMousePressed(QMouseEvent*)));
94 connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)),
95 this, SLOT(onMouseReleased(QMouseEvent*)));
96 connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)),
97 this, SLOT(onMouseMoved(QMouseEvent*)));
98 connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)),
99 this, SLOT(onKeyRelease(QKeyEvent*)));
100 connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)),
101 this, SLOT(onMouseDoubleClick(QMouseEvent*)));
104 PartSet_Module::~PartSet_Module()
108 XGUI_Workshop* PartSet_Module::workshop() const
113 void PartSet_Module::createFeatures()
115 Config_ModuleReader aXMLReader = Config_ModuleReader();
116 aXMLReader.readAll();
117 myFeaturesInFiles = aXMLReader.featuresInFiles();
119 //!! Test registering of validators
120 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
121 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
122 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
123 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
124 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
125 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
126 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
129 void PartSet_Module::featureCreated(QAction* theFeature)
131 connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
134 QStringList PartSet_Module::nestedFeatures(QString)
136 return QStringList();
139 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
141 return myFeaturesInFiles[theFeatureId];
147 void PartSet_Module::onFeatureTriggered()
149 //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(),
150 // myWorkshop->viewer()->activeView());
152 //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(),
153 // myWorkshop->viewer()->activeView());
154 QAction* aCmd = dynamic_cast<QAction*>(sender());
155 //Do nothing on uncheck
156 if(aCmd->isCheckable() && !aCmd->isChecked())
158 launchOperation(aCmd->data().toString());
161 void PartSet_Module::launchOperation(const QString& theCmdId)
163 ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
164 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
166 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
167 // Initialise operation with preliminary selection
168 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
169 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
170 aPreviewOp->initSelection(aSelected, aHighlighted);
172 sendOperation(anOperation);
175 void PartSet_Module::onOperationStarted()
177 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
178 myWorkshop->operationMgr()->currentOperation());
180 XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
181 connect(aPropPanel, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
182 this, SLOT(onStorePoint2D(FeaturePtr, const std::string&)), Qt::UniqueConnection);
186 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
190 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
192 XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
193 //disconnect(aPropPanel, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
194 // this, SLOT(onStorePoint2D(FeaturePtr, const std::string&)));
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*>(
211 myWorkshop->operationMgr()->currentOperation());
213 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
214 // Initialise operation with preliminary selection
215 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
216 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
218 aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
222 void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
224 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
225 myWorkshop->operationMgr()->currentOperation());
227 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
228 // Initialise operation with preliminary selection
229 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
230 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
232 PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
234 if ((!aSketchOp->hasSketchPlane()) && (aSelected.size() > 0)) {
235 Handle(AIS_InteractiveObject) aAIS = aSelected.front().interactive();
236 if ((aAIS == myXPlane->impl<Handle(AIS_InteractiveObject)>()) ||
237 (aAIS == myYPlane->impl<Handle(AIS_InteractiveObject)>()) ||
238 (aAIS == myZPlane->impl<Handle(AIS_InteractiveObject)>()) ) {
240 Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAIS);
241 aSketchOp->setSketchPlane(aAISShape->Shape());
245 aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
249 void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
251 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
252 myWorkshop->operationMgr()->currentOperation());
254 aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView());
257 void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
259 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
260 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
262 aPreviewOp->keyReleased(theEvent->key());
266 void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
268 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
269 myWorkshop->operationMgr()->currentOperation());
272 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
273 // Initialise operation with preliminary selection
274 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
275 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
276 aPreviewOp->mouseDoubleClick(theEvent, myWorkshop->viewer()->activeView(), aSelected,
281 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
284 myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
285 myWorkshop->actionsMgr()->update();
287 //PartSet_TestOCC::testSelection(myWorkshop);
290 void PartSet_Module::onFitAllView()
292 myWorkshop->viewer()->fitAll();
295 void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeature)
297 ModuleBase_Operation* anOperation = createOperation(theName.c_str(),
298 theFeature ? theFeature->getKind() : "");
299 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
302 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
303 // Initialise operation with preliminary selection
304 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
305 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
306 aPreviewOp->initFeature(theFeature);
307 aPreviewOp->initSelection(aSelected, aHighlighted);
309 anOperation->setEditingFeature(theFeature);
311 sendOperation(anOperation);
312 myWorkshop->actionsMgr()->updateCheckState();
315 void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
317 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
318 aViewer->enableMultiselection(theEnabled);
321 void PartSet_Module::onStopSelection(const QFeatureList& theFeatures, const bool isStop)
323 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
325 QFeatureList::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
326 for (; anIt != aLast; anIt++) {
327 activateFeature((*anIt), false);
330 QResultList aResults;
331 foreach(FeaturePtr aFeature, theFeatures) {
332 if (aFeature->results().size() > 0) {
333 const std::list<ResultPtr>& aResList = aFeature->results();
334 std::list<ResultPtr>::const_iterator aIt;
335 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt)
336 aResults.append(*aIt);
339 aDisplayer->stopSelection(aResults, isStop, false);
341 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
342 aViewer->enableSelection(!isStop);
344 aDisplayer->updateViewer();
347 void PartSet_Module::onSetSelection(const QResultList& theFeatures)
349 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
350 aDisplayer->setSelected(theFeatures, false);
351 aDisplayer->updateViewer();
354 void PartSet_Module::onCloseLocalContext()
356 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
357 aDisplayer->closeLocalContexts();
360 void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode)
362 bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
363 // TODO visualizePreview(theFeature, isDisplay, false);
365 ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
367 PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
369 std::list<FeaturePtr> aList = aPrevOp->subFeatures();
370 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
371 std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
373 std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
375 for (; anIt != aLast; anIt++)
376 visualizePreview((*anIt), false, false);
377 aDisplayer->updateViewer();
381 if (theMode == PartSet_OperationSketchBase::FM_Activation ||
382 theMode == PartSet_OperationSketchBase::FM_Deactivation)
383 activateFeature(theFeature, true);
386 ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
387 const std::string& theFeatureKind)
389 // create the operation
390 ModuleBase_Operation* anOperation = 0;
391 if (theCmdId == PartSet_OperationSketch::Type()) {
392 anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
395 ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
397 PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
399 aSketch = aPrevOp->sketch();
400 if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId))
401 anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
402 else if (theCmdId == PartSet_OperationFeatureEditMulti::Type())
403 anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch);
404 else if (theCmdId == PartSet_OperationFeatureEdit::Type())
405 anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
409 anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
412 // set operation description and list of widgets corresponding to the feature xml definition
413 std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
415 std::string aPluginFileName = featureFile(aFeatureKind);
416 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
417 aWdgReader.readAll();
418 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
419 std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
421 //QString aXmlRepr = QString::fromStdString(aXmlCfg);
422 //ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
423 // myWorkshop->moduleConnector());
424 //QWidget* aContent = myWorkshop->propertyPanel()->contentWidget();
425 //qDeleteAll(aContent->children());
426 //aFactory.createWidget(aContent);
428 anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
429 anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
431 //anOperation->setModelWidgets(aXmlRepr.toStdString(), aFactory.getModelWidgets());
433 // connect the operation
434 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
436 connect(aPreviewOp, SIGNAL(featureConstructed(FeaturePtr, int)),
437 this, SLOT(onFeatureConstructed(FeaturePtr, int)));
438 connect(aPreviewOp, SIGNAL(launchOperation(std::string, FeaturePtr)),
439 this, SLOT(onLaunchOperation(std::string, FeaturePtr)));
440 connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
441 this, SLOT(onMultiSelectionEnabled(bool)));
443 connect(aPreviewOp, SIGNAL(stopSelection(const QFeatureList&, const bool)),
444 this, SLOT(onStopSelection(const QFeatureList&, const bool)));
445 connect(aPreviewOp, SIGNAL(setSelection(const QFeatureList&)),
446 this, SLOT(onSetSelection(const QFeatureList&)));
448 connect(aPreviewOp, SIGNAL(closeLocalContext()),
449 this, SLOT(onCloseLocalContext()));
451 PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
453 connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
454 this, SLOT(onPlaneSelected(double, double, double)));
455 connect(aSketchOp, SIGNAL(fitAllView()),
456 this, SLOT(onFitAllView()));
463 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
465 static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
466 Config_PointerMessage aMessage(aModuleEvent, this);
467 aMessage.setPointer(theOperation);
468 Events_Loop::loop()->send(aMessage);
471 boost::shared_ptr<GeomAPI_Shape> getPlane(double theX, double theY, double theZ)
473 boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
474 boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
475 return GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
478 void PartSet_Module::showPlanes()
480 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
481 // Show selection planes
483 boost::shared_ptr<GeomAPI_Shape> aPlaneX = getPlane(1, 0, 0);
484 myXPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
485 myXPlane->createShape(aPlaneX);
486 myXPlane->setColor(Colors::COLOR_RED);
487 myXPlane->setWidth(SKETCH_WIDTH);
490 boost::shared_ptr<GeomAPI_Shape> aPlaneY = getPlane(0, 1, 0);
491 myYPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
492 myYPlane->createShape(aPlaneY);
493 myYPlane->setColor(Colors::COLOR_GREEN);
494 myYPlane->setWidth(SKETCH_WIDTH);
497 boost::shared_ptr<GeomAPI_Shape> aPlaneZ = getPlane(0, 0, 1);
498 myZPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
499 myZPlane->createShape(aPlaneZ);
500 myZPlane->setColor(Colors::COLOR_BLUE);
501 myZPlane->setWidth(SKETCH_WIDTH);
503 aDisplayer->display(myXPlane, false);
504 aDisplayer->display(myYPlane, false);
505 aDisplayer->display(myZPlane, false);
506 aDisplayer->updateViewer();
509 void PartSet_Module::erasePlanes()
511 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
512 aDisplayer->erase(myXPlane, false);
513 aDisplayer->erase(myYPlane, false);
514 aDisplayer->erase(myZPlane, false);
515 aDisplayer->updateViewer();
518 void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
519 const bool isUpdateViewer)
521 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
525 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
529 ResultPtr aResult = theFeature->firstResult();
530 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
532 boost::shared_ptr<SketchPlugin_Feature> aSPFeature =
533 boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
536 //boost::shared_ptr<GeomAPI_AISObject> anAIS =
537 // aSPFeature->getAISObject(aDisplayer->getAISObject(aResult));
538 //aDisplayer->redisplay(aResult, anAIS, false);
542 aDisplayer->erase(aResult, false);
545 aDisplayer->updateViewer();
548 void PartSet_Module::activateFeature(FeaturePtr theFeature, const bool isUpdateViewer)
550 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
551 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
552 /* TODO if (aPreviewOp) {
553 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
554 aDisplayer->activateInLocalContext(theFeature->firstResult(), aPreviewOp->getSelectionModes(theFeature),
559 void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
561 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
565 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
569 FeaturePtr aFeature = aPreviewOp->feature();
570 if (!aFeature || aFeature->getKind() != theCmdId)
573 std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
574 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
575 std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
577 std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
579 for (; anIt != aLast; anIt++) {
580 boost::shared_ptr<SketchPlugin_Feature> aSPFeature =
581 boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
584 visualizePreview((*anIt), true, false);
585 aDisplayer->activateInLocalContext((*anIt)->firstResult(), aModes, false);
587 aDisplayer->updateViewer();
590 void PartSet_Module::editFeature(FeaturePtr theFeature)
595 // if (theFeature->getKind() == SKETCH_KIND) {
596 //FeaturePtr aFeature = theFeature;
597 //if (XGUI_Tools::isModelObject(aFeature)) {
598 // ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
599 // aFeature = aObject->featureRef();
603 onLaunchOperation(theFeature->getKind(), theFeature);
604 updateCurrentPreview(theFeature->getKind());
609 void PartSet_Module::onStorePoint2D(FeaturePtr theFeature, const std::string& theAttribute)
611 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
612 myWorkshop->operationMgr()->currentOperation());
616 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
617 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute(theAttribute));
619 PartSet_Tools::setConstraints(aPreviewOp->sketch(), theFeature, theAttribute,
620 aPoint->x(), aPoint->y());
623 /*bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const
625 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
626 XGUI_ActionsMgr* aActMgr = myWorkshop->actionsMgr();
628 ModuleBase_Operation* aOperation = aOpMgr->currentOperation();
630 return !aActMgr->isNested(theCmdId);
632 PartSet_OperationFeatureEdit* aSketchEdtOp = dynamic_cast<PartSet_OperationFeatureEdit*>(aOperation);
634 QStringList aConstraintList;
635 aConstraintList<<"SketchConstraintDistance"<<"SketchConstraintLength"
636 <<"SketchConstraintRadius"<<"SketchConstraintParallel"<<"SketchConstraintPerpendicular";
637 return aConstraintList.contains(theCmdId);
639 QStringList aList = aActMgr->nestedCommands(aOperation->id());
640 return aList.contains(theCmdId);
643 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
644 Config_WidgetAPI* theWidgetApi, QList<ModuleBase_ModelWidget*>& theModelWidgets)
646 if (theType == "sketch-start-label") {
647 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi);
648 aWgt->setOperationsMgr(myWorkshop->operationMgr());
649 theModelWidgets.append(aWgt);
650 return aWgt->getControl();