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());
244 aSketchOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
246 aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
250 void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
252 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
253 myWorkshop->operationMgr()->currentOperation());
255 aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView());
258 void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
260 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
261 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
263 aPreviewOp->keyReleased(theEvent->key());
267 void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
269 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
270 myWorkshop->operationMgr()->currentOperation());
273 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
274 // Initialise operation with preliminary selection
275 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
276 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
277 aPreviewOp->mouseDoubleClick(theEvent, myWorkshop->viewer()->activeView(), aSelected,
282 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
285 myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
286 myWorkshop->actionsMgr()->update();
288 //PartSet_TestOCC::testSelection(myWorkshop);
291 void PartSet_Module::onFitAllView()
293 myWorkshop->viewer()->fitAll();
296 void PartSet_Module::onLaunchOperation(std::string theName, ObjectPtr theFeature)
298 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
300 qDebug("Warning! Restart operation without feature!");
303 ModuleBase_Operation* anOperation = createOperation(theName.c_str(),
304 theFeature ? aFeature->getKind() : "");
305 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
308 XGUI_Selection* aSelection = myWorkshop->selector()->selection();
309 // Initialise operation with preliminary selection
310 std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
311 std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
312 aPreviewOp->initFeature(aFeature);
313 aPreviewOp->initSelection(aSelected, aHighlighted);
315 anOperation->setEditingFeature(aFeature);
317 sendOperation(anOperation);
318 myWorkshop->actionsMgr()->updateCheckState();
321 void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
323 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
324 aViewer->enableMultiselection(theEnabled);
327 void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
329 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
331 foreach(ObjectPtr aObject, theFeatures) {
332 activateFeature(aObject, false);
335 //ObjectPtr aResults;
336 //foreach(ObjectPtr aFeature, theFeatures) {
337 /* TODO if (aFeature->results().size() > 0) {
338 const std::list<ResultPtr>& aResList = aFeature->results();
339 std::list<ResultPtr>::const_iterator aIt;
340 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt)
341 aResults.append(*aIt);
344 aDisplayer->stopSelection(theFeatures, isStop, false);
346 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
347 aViewer->enableSelection(!isStop);
349 aDisplayer->updateViewer();
352 void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
354 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
355 aDisplayer->setSelected(theFeatures, false);
356 aDisplayer->updateViewer();
359 void PartSet_Module::onCloseLocalContext()
361 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
362 aDisplayer->closeLocalContexts();
365 void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode)
367 bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
368 // TODO visualizePreview(theFeature, isDisplay, false);
370 ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
372 PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
374 std::list<FeaturePtr> aList = aPrevOp->subFeatures();
375 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
376 std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
378 std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
380 for (; anIt != aLast; anIt++)
381 visualizePreview((*anIt), false, false);
382 aDisplayer->updateViewer();
386 if (theMode == PartSet_OperationSketchBase::FM_Activation ||
387 theMode == PartSet_OperationSketchBase::FM_Deactivation)
388 activateFeature(theFeature, true);
391 ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
392 const std::string& theFeatureKind)
394 // create the operation
395 ModuleBase_Operation* anOperation = 0;
396 if (theCmdId == PartSet_OperationSketch::Type()) {
397 anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
400 ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
402 PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
404 aSketch = aPrevOp->sketch();
405 if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId))
406 anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
407 else if (theCmdId == PartSet_OperationFeatureEditMulti::Type())
408 anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch);
409 else if (theCmdId == PartSet_OperationFeatureEdit::Type())
410 anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
414 anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
417 // set operation description and list of widgets corresponding to the feature xml definition
418 std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
420 std::string aPluginFileName = featureFile(aFeatureKind);
421 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
422 aWdgReader.readAll();
423 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
424 std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
426 //QString aXmlRepr = QString::fromStdString(aXmlCfg);
427 //ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
428 // myWorkshop->moduleConnector());
429 //QWidget* aContent = myWorkshop->propertyPanel()->contentWidget();
430 //qDeleteAll(aContent->children());
431 //aFactory.createWidget(aContent);
433 anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
434 anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
436 //anOperation->setModelWidgets(aXmlRepr.toStdString(), aFactory.getModelWidgets());
438 // connect the operation
439 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
441 connect(aPreviewOp, SIGNAL(featureConstructed(FeaturePtr, int)),
442 this, SLOT(onFeatureConstructed(FeaturePtr, int)));
443 connect(aPreviewOp, SIGNAL(launchOperation(std::string, ObjectPtr)),
444 this, SLOT(onLaunchOperation(std::string, ObjectPtr)));
445 connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
446 this, SLOT(onMultiSelectionEnabled(bool)));
448 connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)),
449 this, SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
450 connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)),
451 this, SLOT(onSetSelection(const QList<ObjectPtr>&)));
453 connect(aPreviewOp, SIGNAL(closeLocalContext()),
454 this, SLOT(onCloseLocalContext()));
456 PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
458 connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
459 this, SLOT(onPlaneSelected(double, double, double)));
460 connect(aSketchOp, SIGNAL(fitAllView()),
461 this, SLOT(onFitAllView()));
468 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
470 static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
471 Config_PointerMessage aMessage(aModuleEvent, this);
472 aMessage.setPointer(theOperation);
473 Events_Loop::loop()->send(aMessage);
476 boost::shared_ptr<GeomAPI_Shape> getPlane(double theX, double theY, double theZ)
478 boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
479 boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
480 return GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
483 void PartSet_Module::showPlanes()
485 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
486 // Show selection planes
488 boost::shared_ptr<GeomAPI_Shape> aPlaneX = getPlane(1, 0, 0);
489 myXPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
490 myXPlane->createShape(aPlaneX);
491 myXPlane->setColor(Colors::COLOR_RED);
492 myXPlane->setWidth(SKETCH_WIDTH);
495 boost::shared_ptr<GeomAPI_Shape> aPlaneY = getPlane(0, 1, 0);
496 myYPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
497 myYPlane->createShape(aPlaneY);
498 myYPlane->setColor(Colors::COLOR_GREEN);
499 myYPlane->setWidth(SKETCH_WIDTH);
502 boost::shared_ptr<GeomAPI_Shape> aPlaneZ = getPlane(0, 0, 1);
503 myZPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
504 myZPlane->createShape(aPlaneZ);
505 myZPlane->setColor(Colors::COLOR_BLUE);
506 myZPlane->setWidth(SKETCH_WIDTH);
508 aDisplayer->display(myXPlane, false);
509 aDisplayer->display(myYPlane, false);
510 aDisplayer->display(myZPlane, false);
511 aDisplayer->updateViewer();
514 void PartSet_Module::erasePlanes()
516 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
517 aDisplayer->erase(myXPlane, false);
518 aDisplayer->erase(myYPlane, false);
519 aDisplayer->erase(myZPlane, false);
520 aDisplayer->updateViewer();
523 void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
524 const bool isUpdateViewer)
526 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
530 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
534 ResultPtr aResult = theFeature->firstResult();
535 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
537 boost::shared_ptr<SketchPlugin_Feature> aSPFeature =
538 boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
540 PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
541 if (aSketchOp && !aSketchOp->hasSketchPlane())
546 aDisplayer->erase(aResult, false);
549 aDisplayer->updateViewer();
552 void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer)
554 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
555 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
557 PartSet_OperationSketch* aOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
559 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
560 aDisplayer->activateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
566 void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
568 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
572 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
576 FeaturePtr aFeature = aPreviewOp->feature();
577 if (!aFeature || aFeature->getKind() != theCmdId)
580 std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
581 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
582 std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
584 std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
586 for (; anIt != aLast; anIt++) {
587 boost::shared_ptr<SketchPlugin_Feature> aSPFeature =
588 boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
591 visualizePreview((*anIt), true, false);
592 aDisplayer->activateInLocalContext((*anIt)->firstResult(), aModes, false);
594 aDisplayer->updateViewer();
597 void PartSet_Module::editFeature(FeaturePtr theFeature)
602 // if (theFeature->getKind() == SKETCH_KIND) {
603 //FeaturePtr aFeature = theFeature;
604 //if (XGUI_Tools::isModelObject(aFeature)) {
605 // ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
606 // aFeature = aObject->featureRef();
610 onLaunchOperation(theFeature->getKind(), theFeature);
611 updateCurrentPreview(theFeature->getKind());
616 void PartSet_Module::onStorePoint2D(FeaturePtr theFeature, const std::string& theAttribute)
618 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
619 myWorkshop->operationMgr()->currentOperation());
623 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
624 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute(theAttribute));
626 PartSet_Tools::setConstraints(aPreviewOp->sketch(), theFeature, theAttribute,
627 aPoint->x(), aPoint->y());
630 /*bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const
632 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
633 XGUI_ActionsMgr* aActMgr = myWorkshop->actionsMgr();
635 ModuleBase_Operation* aOperation = aOpMgr->currentOperation();
637 return !aActMgr->isNested(theCmdId);
639 PartSet_OperationFeatureEdit* aSketchEdtOp = dynamic_cast<PartSet_OperationFeatureEdit*>(aOperation);
641 QStringList aConstraintList;
642 aConstraintList<<"SketchConstraintDistance"<<"SketchConstraintLength"
643 <<"SketchConstraintRadius"<<"SketchConstraintParallel"<<"SketchConstraintPerpendicular";
644 return aConstraintList.contains(theCmdId);
646 QStringList aList = aActMgr->nestedCommands(aOperation->id());
647 return aList.contains(theCmdId);
650 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
651 Config_WidgetAPI* theWidgetApi, QList<ModuleBase_ModelWidget*>& theModelWidgets)
653 if (theType == "sketch-start-label") {
654 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi);
655 aWgt->setOperationsMgr(myWorkshop->operationMgr());
656 theModelWidgets.append(aWgt);
657 return aWgt->getControl();