1 #include "PartSet_Module.h"
2 //#include <PartSet_OperationSketch.h>
3 //#include <PartSet_OperationFeatureCreate.h>
4 //#include <PartSet_OperationFeatureEdit.h>
5 //#include <PartSet_Listener.h>
6 //#include <PartSet_TestOCC.h>
7 #include "PartSet_WidgetSketchLabel.h"
8 #include "PartSet_Validators.h"
9 #include "PartSet_Tools.h"
10 #include "PartSet_WidgetPoint2D.h"
11 #include "PartSet_WidgetPoint2dDistance.h"
12 #include "PartSet_WidgetShapeSelector.h"
14 #include <ModuleBase_Operation.h>
15 #include <ModuleBase_IViewer.h>
16 #include <ModuleBase_IViewWindow.h>
17 #include <ModuleBase_IPropertyPanel.h>
18 //#include <ModuleBase_OperationDescription.h>
19 //#include <ModuleBase_WidgetFactory.h>
21 #include <ModelAPI_Object.h>
22 #include <ModelAPI_Events.h>
23 #include <ModelAPI_Validator.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_Session.h>
27 #include <GeomDataAPI_Point2D.h>
28 #include <GeomDataAPI_Point.h>
29 #include <GeomDataAPI_Dir.h>
31 #include <XGUI_MainWindow.h>
32 #include <XGUI_Displayer.h>
33 #include <XGUI_Viewer.h>
34 #include <XGUI_Workshop.h>
35 #include <XGUI_OperationMgr.h>
36 #include <XGUI_ViewPort.h>
37 #include <XGUI_ActionsMgr.h>
38 #include <XGUI_ViewerProxy.h>
39 #include <XGUI_ContextMenuMgr.h>
40 #include <XGUI_PropertyPanel.h>
41 #include <XGUI_ModuleConnector.h>
42 #include <XGUI_Tools.h>
44 #include <SketchPlugin_Line.h>
45 #include <SketchPlugin_Sketch.h>
46 #include <SketchPlugin_Point.h>
47 #include <SketchPlugin_Arc.h>
48 #include <SketchPlugin_Circle.h>
49 #include <SketchPlugin_ConstraintLength.h>
50 #include <SketchPlugin_ConstraintDistance.h>
51 #include <SketchPlugin_ConstraintParallel.h>
52 #include <SketchPlugin_ConstraintPerpendicular.h>
53 #include <SketchPlugin_ConstraintRadius.h>
54 #include <SketchPlugin_ConstraintRigid.h>
56 //#include <Config_PointerMessage.h>
57 //#include <Config_ModuleReader.h>
58 //#include <Config_WidgetReader.h>
59 //#include <Events_Loop.h>
60 //#include <Events_Message.h>
61 //#include <Events_Error.h>
63 //#include <GeomAPI_Shape.h>
64 //#include <GeomAPI_AISObject.h>
65 //#include <AIS_Shape.hxx>
66 //#include <AIS_DimensionSelectionMode.hxx>
68 #include <StdSelect_TypeOfFace.hxx>
71 #include <QMouseEvent>
75 #include <GeomAlgoAPI_FaceBuilder.h>
76 #include <GeomDataAPI_Dir.h>
83 /*!Create and return new instance of XGUI_Module*/
84 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
86 return new PartSet_Module(theWshop);
89 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
90 : ModuleBase_IModule(theWshop),
91 myIsDragging(false), myRestartingMode(true), myDragDone(false)
93 //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
94 ModuleBase_IViewer* aViewer = aViewer = theWshop->viewer();
95 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
96 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
98 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
99 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
101 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
102 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
104 //myListener = new PartSet_Listener(this);
106 // connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)),
107 // this, SLOT(onOperationStarted(ModuleBase_Operation*)));
109 // connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
110 // SLOT(onOperationStopped(ModuleBase_Operation*)));
112 //XGUI_Workshop* aXWshop = xWorkshop();
113 //XGUI_ContextMenuMgr* aContextMenuMgr = aXWshop->contextMenuMgr();
114 //connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
115 // SLOT(onContextMenuCommand(const QString&, bool)));
119 PartSet_Module::~PartSet_Module()
123 void PartSet_Module::registerValidators()
125 //Registering of validators
126 SessionPtr aMgr = ModelAPI_Session::get();
127 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
128 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
129 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
130 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
131 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
132 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
136 void PartSet_Module::onOperationComitted(ModuleBase_Operation* theOperation)
138 if (theOperation->isEditOperation())
140 /// Restart sketcher operations automatically
141 FeaturePtr aFeature = theOperation->feature();
142 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
143 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
144 if (aSPFeature && myRestartingMode) {
145 myLastOperationId = theOperation->id();
146 myLastFeature = theOperation->feature();
147 launchOperation(myLastOperationId);
149 breakOperationSequence();
153 void PartSet_Module::breakOperationSequence()
155 myLastOperationId = "";
156 myLastFeature = FeaturePtr();
157 myRestartingMode = false;
161 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
163 breakOperationSequence();
166 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
168 myRestartingMode = true;
169 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
170 // Display all sketcher sub-Objects
171 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
172 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
173 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
175 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
176 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
177 std::list<ResultPtr> aResults = aFeature->results();
178 std::list<ResultPtr>::const_iterator aIt;
179 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
180 aDisplayer->display((*aIt), false);
182 aDisplayer->display(aFeature);
184 // Hide sketcher result
185 std::list<ResultPtr> aResults = myCurrentSketch->results();
186 std::list<ResultPtr>::const_iterator aIt;
187 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
188 aDisplayer->erase((*aIt), false);
190 aDisplayer->erase(myCurrentSketch);
194 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
196 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
197 // Hide all sketcher sub-Objects
198 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
199 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
201 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
202 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
203 std::list<ResultPtr> aResults = aFeature->results();
204 std::list<ResultPtr>::const_iterator aIt;
205 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
206 aDisplayer->erase((*aIt), false);
208 aDisplayer->erase(aFeature, false);
210 // Display sketcher result
211 std::list<ResultPtr> aResults = myCurrentSketch->results();
212 std::list<ResultPtr>::const_iterator aIt;
213 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
214 aDisplayer->display((*aIt), false);
216 aDisplayer->display(myCurrentSketch);
218 myCurrentSketch = CompositeFeaturePtr();
224 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
226 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
227 ModuleBase_ModelWidget* aWgt = theOperation->propertyPanel()->activeWidget();
228 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
229 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
231 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
232 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
233 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
235 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
236 PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(),
237 SketchPlugin_Line::START_ID(), aPoint->x(), aPoint->y());
238 theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
246 void PartSet_Module::onSelectionChanged()
248 // Activate edit operation for sketcher objects
249 //ModuleBase_ISelection* aSelect = myWorkshop->selection();
250 //QObjectPtrList aObjects = aSelect->selectedPresentations();
251 //if (aObjects.size() == 1) {
252 // FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first());
254 // std::shared_ptr<SketchPlugin_Feature> aSPFeature =
255 // std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
257 // editFeature(aSPFeature);
263 //ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId)
265 // ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
267 // // If the current operation is sketcher sub-operation then we have to create
268 // // Costomized operation
269 // if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
270 // PartSet_Operation* aPSOp = new PartSet_Operation(theFeatureId.c_str(), this);
271 // aPSOp->setWorkshop(myWorkshop);
272 // connect(myWorkshop, SIGNAL(selectionChanged()), aPSOp, SLOT(onSelectionChanged()));
276 // return ModuleBase_IModule::getNewOperation(theFeatureId);
280 void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
282 if (!(theEvent->buttons() & Qt::LeftButton))
284 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
285 // Use only for sketch operations
286 if (aOperation && myCurrentSketch) {
287 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
290 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
291 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
293 // Avoid non-sketch operations
297 bool isEditing = aOperation->isEditOperation();
299 // Ignore creation sketch operation
300 if ((!isSketcher) && (!isEditing))
303 // Remember highlighted objects for editing
304 ModuleBase_ISelection* aSelect = myWorkshop->selection();
305 QList<ModuleBase_ViewerPrs> aObjects = aSelect->getHighlighted();
306 myEditingFeatures.clear();
307 if (aObjects.size() > 0) {
308 foreach(ModuleBase_ViewerPrs aPrs, aObjects) {
309 FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first().object());
311 myEditingFeatures.append(aFeature);
314 // If nothing highlighted - return
315 if (myEditingFeatures.size() == 0)
319 CompositeFeaturePtr aSketch =
320 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aOperation->feature());
321 if (!PartSet_Tools::sketchPlane(aSketch))
324 //myCurrentSketch = aOperation->feature();
326 get2dPoint(theWnd, theEvent, myCurX, myCurY);
328 myWorkshop->viewer()->enableSelection(false);
332 } else if (isSketchOpe && isEditing) {
335 //myCurrentSketch = aOperation->parentFeature();
337 get2dPoint(theWnd, theEvent, myCurX, myCurY);
339 myWorkshop->viewer()->enableSelection(false);
341 QTimer::singleShot(10, this, SLOT(launchEditing()));
347 void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
348 double& theX, double& theY)
350 Handle(V3d_View) aView = theWnd->v3dView();
351 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
352 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
356 void PartSet_Module::launchEditing()
358 if (myEditingFeatures.size() == 1) {
359 FeaturePtr aFeature = myEditingFeatures.first();
360 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
361 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
363 editFeature(aSPFeature);
368 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
371 myIsDragging = false;
372 myWorkshop->viewer()->enableSelection(true);
374 myWorkshop->currentOperation()->commit();
379 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
382 Handle(V3d_View) aView = theWnd->v3dView();
383 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
385 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
386 double dX = myCurX - aX;
387 double dY = myCurY - aY;
389 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
390 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
391 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
392 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
393 PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
395 aWgt2d->setPoint(aWgt2d->x() - dX, aWgt2d->y() - dY);
405 QStringList PartSet_Module::sketchOperationIdList() const
408 aIds << SketchPlugin_Line::ID().c_str();
409 aIds << SketchPlugin_Point::ID().c_str();
410 aIds << SketchPlugin_Arc::ID().c_str();
411 aIds << SketchPlugin_Circle::ID().c_str();
412 aIds << SketchPlugin_ConstraintLength::ID().c_str();
413 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
414 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
415 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
416 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
417 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
421 void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
423 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
424 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
425 /// If last line finished on vertex the lines creation sequence has to be break
426 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
427 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
428 if (aWidgets.last() == aPanel->activeWidget()) {
429 breakOperationSequence();
430 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aPanel->activeWidget());
431 PartSet_Tools::setConstraints(myCurrentSketch, aOperation->feature(),
432 SketchPlugin_Line::END_ID(), aPnt2dWgt->x(), aPnt2dWgt->y());
438 //void PartSet_Module::featureCreated(QAction* theFeature)
440 // connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
443 //std::string PartSet_Module::featureFile(const std::string& theFeatureId)
445 // return myFeaturesInFiles[theFeatureId];
451 //void PartSet_Module::onFeatureTriggered()
453 // QAction* aCmd = dynamic_cast<QAction*>(sender());
454 // //Do nothing on uncheck
455 // if (aCmd->isCheckable() && !aCmd->isChecked())
457 // launchOperation(aCmd->data().toString());
461 //void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
463 // XGUI_Workshop* aXWshp = xWorkshop();
464 // XGUI_Displayer* aDisplayer = aXWshp->displayer();
465 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
467 // XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
468 // connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
469 // SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
471 // //aDisplayer->deactivateObjectsOutOfContext();
472 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
474 // if (aSketchOp->isEditOperation()) {
475 // setSketchingMode(getSketchPlane(aSketchOp->feature()));
477 // aDisplayer->openLocalContext();
478 // aDisplayer->activateObjectsOutOfContext(QIntList());
479 // myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
480 // aDisplayer->addSelectionFilter(myPlaneFilter);
481 // QIntList aModes = sketchSelectionModes(aPreviewOp->feature());
482 // aDisplayer->setSelectionModes(aModes);
488 //void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
490 // if (!theOperation)
492 // XGUI_Workshop* aXWshp = xWorkshop();
493 // XGUI_Displayer* aDisplayer = aXWshp->displayer();
494 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
496 // XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
498 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
500 // aDisplayer->closeLocalContexts();
502 // PartSet_OperationFeatureCreate* aCreationOp =
503 // dynamic_cast<PartSet_OperationFeatureCreate*>(aPreviewOp);
504 // if (aCreationOp) {
505 // // Activate just created object for selection
506 // FeaturePtr aFeature = aCreationOp->feature();
507 // QIntList aModes = sketchSelectionModes(aFeature);
508 // const std::list<ResultPtr>& aResults = aFeature->results();
509 // std::list<ResultPtr>::const_iterator anIt, aLast = aResults.end();
510 // for (anIt = aResults.begin(); anIt != aLast; anIt++) {
511 // aDisplayer->activate(*anIt, aModes);
513 // aDisplayer->activate(aFeature, aModes);
514 // aDisplayer->clearSelected();
518 // // Activate results of current feature for selection
519 // //FeaturePtr aFeature = theOperation->feature();
520 // //XGUI_Displayer* aDisplayer = aXWshp->displayer();
521 // //std::list<ResultPtr> aResults = aFeature->results();
522 // //std::list<ResultPtr>::const_iterator aIt;
523 // //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
524 // // aDisplayer->activate(*aIt);
529 //void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
531 // QList<ObjectPtr> aFeatures = workshop()->selection()->selectedObjects();
532 // if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
533 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
535 // editFeature(aFeature);
539 //void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
541 // XGUI_Workshop* aXWshp = xWorkshop();
542 // PartSet_OperationSketchBase* aPreviewOp =
543 // dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
545 // ModuleBase_ISelection* aSelection = workshop()->selection();
546 // aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection);
550 //void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
552 // PartSet_OperationSketchBase* aPreviewOp =
553 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
555 // ModuleBase_ISelection* aSelection = workshop()->selection();
556 // // Initialise operation with preliminary selection
557 // aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection);
561 //void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
563 // PartSet_OperationSketchBase* aPreviewOp =
564 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
566 // aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer());
569 //void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
571 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
572 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
574 // aPreviewOp->keyReleased(theEvent->key());
578 //void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
580 // PartSet_OperationSketchBase* aPreviewOp =
581 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
582 // Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
583 // if (aPreviewOp && (!aView.IsNull())) {
584 // ModuleBase_ISelection* aSelection = workshop()->selection();
585 // // Initialise operation with preliminary selection
586 // aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection);
590 //void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
592 // myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
595 //void PartSet_Module::onSketchLaunched()
597 // xWorkshop()->actionsMgr()->update();
598 // // Set working plane
599 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
600 // FeaturePtr aSketch = anOperation->feature();
601 // setSketchingMode(getSketchPlane(aSketch));
604 //void PartSet_Module::onFitAllView()
606 // myWorkshop->viewer()->fitAll();
609 //void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject)
611 // FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
613 // std::string aKind = aFeature ? aFeature->getKind() : "";
614 // ModuleBase_Operation* anOperation = createOperation(theName, aKind);
616 // PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
618 // PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast<PartSet_OperationFeatureCreate*>(anOperation);
620 // aCreateOp->initFeature(aFeature);
622 // anOperation->setFeature(aFeature);
624 // ModuleBase_ISelection* aSelection = workshop()->selection();
625 // // Initialise operation with preliminary selection
626 // aSketchOp->initSelection(aSelection, myWorkshop->viewer());
627 // } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation
628 // anOperation->setFeature(aFeature);
629 // ////Deactivate result of current feature in order to avoid its selection
630 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
631 // std::list<ResultPtr> aResults = aFeature->results();
632 // std::list<ResultPtr>::const_iterator aIt;
633 // for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
634 // aDisplayer->deactivate(*aIt);
637 // sendOperation(anOperation);
638 // xWorkshop()->actionsMgr()->updateCheckState();
641 //void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
643 // ModuleBase_IViewer* aViewer = myWorkshop->viewer();
644 // aViewer->enableMultiselection(theEnabled);
647 //void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
649 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
651 // // foreach(ObjectPtr aObject, theFeatures) {
652 // // activateFeature(aObject);
655 // aDisplayer->stopSelection(theFeatures, isStop, false);
657 // ModuleBase_IViewer* aViewer = myWorkshop->viewer();
658 // aViewer->enableSelection(!isStop);
660 // aDisplayer->updateViewer();
663 //void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
665 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
666 // aDisplayer->setSelected(theFeatures, false);
667 // aDisplayer->updateViewer();
670 //void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
672 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
673 // if (!myPlaneFilter.IsNull()) {
674 // aDisplayer->removeSelectionFilter(myPlaneFilter);
675 // myPlaneFilter.Nullify();
678 // // Clear standard selection modes
679 // aDisplayer->setSelectionModes(aModes);
680 // aDisplayer->openLocalContext();
683 // mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
684 // aDisplayer->addSelectionFilter(mySketchFilter);
686 // // Get default selection modes
687 // aModes = sketchSelectionModes(ObjectPtr());
688 // aDisplayer->activateObjectsOutOfContext(aModes);
691 //void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
693 // bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
694 // ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
695 // PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
697 // std::list<FeaturePtr> aList = aPrevOp->subFeatures();
698 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
699 // QIntList aModes = sketchSelectionModes(aPrevOp->feature());
700 // std::list<FeaturePtr>::iterator aSFIt;
701 // for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
702 // std::list<ResultPtr> aResults = (*aSFIt)->results();
703 // std::list<ResultPtr>::iterator aIt;
704 // for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
706 // aDisplayer->erase((*aIt), false);
709 // aDisplayer->erase((*aSFIt), false);
711 // //aDisplayer->deactivateObjectsOutOfContext();
714 // ModelAPI_EventCreator::get()->sendUpdated(
715 // theFeature, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
718 //ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
719 // const std::string& theFeatureKind)
721 // // create the operation
722 // ModuleBase_Operation* anOperation = 0;
723 // if (theCmdId == PartSet_OperationSketch::Type()) {
724 // anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
726 // ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
727 // CompositeFeaturePtr aSketch;
728 // PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
730 // aSketch = aPrevOp->sketch();
732 // if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) {
733 // anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
734 // } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) {
735 // anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
739 // if (!anOperation) {
740 // anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
743 // // set operation description and list of widgets corresponding to the feature xml definition
744 // std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
746 // std::string aPluginFileName = featureFile(aFeatureKind);
747 // Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
748 // aWdgReader.readAll();
749 // std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
750 // std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
752 // anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
753 // anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
755 // // connect the operation
756 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
758 // connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this,
759 // SLOT(onFeatureConstructed(ObjectPtr, int)));
760 // connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
761 // SLOT(onRestartOperation(std::string, ObjectPtr)));
762 // // If manage multi selection the it will be impossible to select more then one
763 // // object under operation Edit
764 //// connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
765 //// SLOT(onMultiSelectionEnabled(bool)));
767 // connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
768 // SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
769 // connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
770 // SLOT(onSetSelection(const QList<ObjectPtr>&)));
772 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
774 // connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
775 // SLOT(onPlaneSelected(double, double, double)));
776 // connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
777 // connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched()));
781 // return anOperation;
785 //void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
787 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
791 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
795 // FeaturePtr aFeature = aPreviewOp->feature();
796 // if (!aFeature || aFeature->getKind() != theCmdId)
799 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
800 // // Hide result of sketch
801 // std::list<ResultPtr> aResults = aFeature->results();
802 // std::list<ResultPtr>::const_iterator aIt;
803 // for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt)
804 // aDisplayer->erase(*aIt, false);
806 // std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
808 // std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
809 // for (; anIt != aLast; anIt++) {
810 // std::shared_ptr<SketchPlugin_Feature> aSPFeature = std::dynamic_pointer_cast<
811 // SketchPlugin_Feature>(*anIt);
814 // std::list<ResultPtr> aResults = aSPFeature->results();
815 // std::list<ResultPtr>::const_iterator aRIt;
816 // for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
817 // aDisplayer->display((*aRIt), false);
818 // aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt)));
820 // aDisplayer->display(aSPFeature, false);
821 // aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature));
823 // aDisplayer->updateViewer();
826 //void PartSet_Module::editFeature(FeaturePtr theFeature)
831 // if (theFeature->getKind() == SKETCH_KIND) {
832 //FeaturePtr aFeature = theFeature;
833 //if (XGUI_Tools::isModelObject(aFeature)) {
834 // ObjectPtr aObject = std::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
835 // aFeature = aObject->featureRef();
839 // onRestartOperation(theFeature->getKind(), theFeature);
840 // updateCurrentPreview(theFeature->getKind());
845 //void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute)
847 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
849 // PartSet_OperationSketchBase* aPreviewOp =
850 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
854 // std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
855 // aFeature->data()->attribute(theAttribute));
857 // PartSet_Tools::setConstraints(aPreviewOp->sketch(), aFeature, theAttribute, aPoint->x(),
861 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
862 Config_WidgetAPI* theWidgetApi, std::string theParentId,
863 QList<ModuleBase_ModelWidget*>& theModelWidgets)
865 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
866 XGUI_Workshop* aWorkshop = aConnector->workshop();
867 if (theType == "sketch-start-label") {
868 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
869 aWgt->setWorkshop(aWorkshop);
870 theModelWidgets.append(aWgt);
871 return aWgt->getControl();
873 } else if (theType == "sketch-2dpoint_selector") {
874 PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
875 aWgt->setWorkshop(aWorkshop);
876 aWgt->setSketch(myCurrentSketch);
878 connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)),
879 this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
881 theModelWidgets.append(aWgt);
882 return aWgt->getControl();
884 } if (theType == "point2ddistance") {
885 PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
886 aWgt->setWorkshop(aWorkshop);
887 aWgt->setSketch(myCurrentSketch);
889 theModelWidgets.append(aWgt);
890 return aWgt->getControl();
892 } if (theType == "sketch_shape_selector") {
893 PartSet_WidgetShapeSelector* aWgt =
894 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
895 aWgt->setSketcher(myCurrentSketch);
897 theModelWidgets.append(aWgt);
898 return aWgt->getControl();
905 //XGUI_Workshop* PartSet_Module::xWorkshop() const
907 // XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
909 // return aConnector->workshop();
915 //QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
918 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
920 // if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
921 // aModes.append(TopAbs_FACE);
923 // } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
924 // aModes.append(AIS_DSM_Text);
925 // aModes.append(AIS_DSM_Line);
929 // aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
930 // aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
935 //gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
937 // DataPtr aData = theSketch->data();
938 // std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
939 // aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
940 // std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
941 // aData->attribute(SketchPlugin_Sketch::NORM_ID()));
942 // gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
943 // gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
944 // return gp_Pln(aOrig, aDir);
948 //void PartSet_Module::onSelectionChanged()
950 // ModuleBase_ISelection* aSelect = myWorkshop->selection();
951 // QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
952 // // We need to stop edit operation if selection is cleared
953 // if (aSelected.size() == 0) {
954 // // do not perform commit of the current edit operation here, because
955 // // this functionality is realized inside this operation
956 // /*PartSet_OperationFeatureEdit* anEditOp =
957 // dynamic_cast<PartSet_OperationFeatureEdit*>(myWorkshop->currentOperation());
960 // anEditOp->commit();*/
962 // PartSet_OperationSketchBase* aSketchOp =
963 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
965 // aSketchOp->selectionChanged(aSelect);