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_Operation.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>
50 //#include <Config_PointerMessage.h>
51 //#include <Config_ModuleReader.h>
52 //#include <Config_WidgetReader.h>
53 //#include <Events_Loop.h>
54 //#include <Events_Message.h>
55 //#include <Events_Error.h>
57 //#include <GeomAPI_Shape.h>
58 //#include <GeomAPI_AISObject.h>
59 //#include <AIS_Shape.hxx>
60 //#include <AIS_DimensionSelectionMode.hxx>
62 #include <StdSelect_TypeOfFace.hxx>
65 #include <QMouseEvent>
69 #include <GeomAlgoAPI_FaceBuilder.h>
70 #include <GeomDataAPI_Dir.h>
77 /*!Create and return new instance of XGUI_Module*/
78 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
80 return new PartSet_Module(theWshop);
83 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
84 : ModuleBase_IModule(theWshop),
85 myIsDragging(false), myRestartingMode(true), myDragDone(false)
87 //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
88 ModuleBase_IViewer* aViewer = aViewer = theWshop->viewer();
89 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
90 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
92 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
93 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
95 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
96 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
98 //myListener = new PartSet_Listener(this);
100 // connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)),
101 // this, SLOT(onOperationStarted(ModuleBase_Operation*)));
103 // connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
104 // SLOT(onOperationStopped(ModuleBase_Operation*)));
106 //XGUI_Workshop* aXWshop = xWorkshop();
107 //XGUI_ContextMenuMgr* aContextMenuMgr = aXWshop->contextMenuMgr();
108 //connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
109 // SLOT(onContextMenuCommand(const QString&, bool)));
113 PartSet_Module::~PartSet_Module()
117 void PartSet_Module::registerValidators()
119 //Registering of validators
120 SessionPtr aMgr = ModelAPI_Session::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);
130 void PartSet_Module::onOperationComitted(ModuleBase_Operation* theOperation)
132 if (theOperation->isEditOperation())
134 /// Restart sketcher operations automatically
135 FeaturePtr aFeature = theOperation->feature();
136 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
137 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
138 if (aSPFeature && myRestartingMode) {
139 myLastOperationId = theOperation->id();
140 myLastFeature = theOperation->feature();
141 launchOperation(myLastOperationId);
143 breakOperationSequence();
147 void PartSet_Module::breakOperationSequence()
149 myLastOperationId = "";
150 myLastFeature = FeaturePtr();
151 myRestartingMode = false;
155 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
157 breakOperationSequence();
160 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
162 myRestartingMode = true;
163 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
164 // Display all sketcher sub-Objects
165 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
166 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
167 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
169 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
170 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
171 std::list<ResultPtr> aResults = aFeature->results();
172 std::list<ResultPtr>::const_iterator aIt;
173 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
174 aDisplayer->display((*aIt), false);
176 aDisplayer->display(aFeature);
178 // Hide sketcher result
179 std::list<ResultPtr> aResults = myCurrentSketch->results();
180 std::list<ResultPtr>::const_iterator aIt;
181 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
182 aDisplayer->erase((*aIt), false);
184 aDisplayer->erase(myCurrentSketch);
188 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
190 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
191 // Hide all sketcher sub-Objects
192 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
193 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
195 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
196 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
197 std::list<ResultPtr> aResults = aFeature->results();
198 std::list<ResultPtr>::const_iterator aIt;
199 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
200 aDisplayer->erase((*aIt), false);
202 aDisplayer->erase(aFeature, false);
204 // Display sketcher result
205 std::list<ResultPtr> aResults = myCurrentSketch->results();
206 std::list<ResultPtr>::const_iterator aIt;
207 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
208 aDisplayer->display((*aIt), false);
210 aDisplayer->display(myCurrentSketch);
212 myCurrentSketch = CompositeFeaturePtr();
218 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
220 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
221 ModuleBase_ModelWidget* aWgt = theOperation->propertyPanel()->activeWidget();
222 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
223 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
225 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
226 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
227 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
229 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
230 PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(),
231 SketchPlugin_Line::START_ID(), aPoint->x(), aPoint->y());
232 theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
240 void PartSet_Module::onSelectionChanged()
242 // Activate edit operation for sketcher objects
243 //ModuleBase_ISelection* aSelect = myWorkshop->selection();
244 //QObjectPtrList aObjects = aSelect->selectedPresentations();
245 //if (aObjects.size() == 1) {
246 // FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first());
248 // std::shared_ptr<SketchPlugin_Feature> aSPFeature =
249 // std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
251 // editFeature(aSPFeature);
257 //ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId)
259 // ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
261 // // If the current operation is sketcher sub-operation then we have to create
262 // // Costomized operation
263 // if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
264 // PartSet_Operation* aPSOp = new PartSet_Operation(theFeatureId.c_str(), this);
265 // aPSOp->setWorkshop(myWorkshop);
266 // connect(myWorkshop, SIGNAL(selectionChanged()), aPSOp, SLOT(onSelectionChanged()));
270 // return ModuleBase_IModule::getNewOperation(theFeatureId);
274 void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
276 if (!(theEvent->buttons() & Qt::LeftButton))
278 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
279 // Use only for sketch operations
280 if (aOperation && myCurrentSketch) {
281 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
284 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
285 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
287 // Avoid non-sketch operations
291 bool isEditing = aOperation->isEditOperation();
293 // Ignore creation sketch operation
294 if ((!isSketcher) && (!isEditing))
297 // Remember highlighted objects for editing
298 ModuleBase_ISelection* aSelect = myWorkshop->selection();
299 QList<ModuleBase_ViewerPrs> aObjects = aSelect->getHighlighted();
300 myEditingFeatures.clear();
301 if (aObjects.size() > 0) {
302 foreach(ModuleBase_ViewerPrs aPrs, aObjects) {
303 FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first().object());
305 myEditingFeatures.append(aFeature);
308 // If nothing highlighted - return
309 if (myEditingFeatures.size() == 0)
313 CompositeFeaturePtr aSketch =
314 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aOperation->feature());
315 if (!PartSet_Tools::sketchPlane(aSketch))
318 //myCurrentSketch = aOperation->feature();
320 get2dPoint(theWnd, theEvent, myCurX, myCurY);
322 myWorkshop->viewer()->enableSelection(false);
326 } else if (isSketchOpe && isEditing) {
329 //myCurrentSketch = aOperation->parentFeature();
331 get2dPoint(theWnd, theEvent, myCurX, myCurY);
333 myWorkshop->viewer()->enableSelection(false);
335 QTimer::singleShot(10, this, SLOT(launchEditing()));
341 void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
342 double& theX, double& theY)
344 Handle(V3d_View) aView = theWnd->v3dView();
345 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
346 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
350 void PartSet_Module::launchEditing()
352 if (myEditingFeatures.size() == 1) {
353 FeaturePtr aFeature = myEditingFeatures.first();
354 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
355 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
357 editFeature(aSPFeature);
362 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
365 myIsDragging = false;
366 myWorkshop->viewer()->enableSelection(true);
368 myWorkshop->currentOperation()->commit();
373 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
376 Handle(V3d_View) aView = theWnd->v3dView();
377 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
379 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
380 double dX = myCurX - aX;
381 double dY = myCurY - aY;
383 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
384 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
385 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
386 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
387 PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
389 aWgt2d->setPoint(aWgt2d->x() - dX, aWgt2d->y() - dY);
399 QStringList PartSet_Module::sketchOperationIdList() const
402 aIds << SketchPlugin_Sketch::ID().c_str();
403 aIds << SketchPlugin_Line::ID().c_str();
404 aIds << SketchPlugin_Point::ID().c_str();
405 aIds << SketchPlugin_Arc::ID().c_str();
406 aIds << SketchPlugin_Circle::ID().c_str();
410 void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
412 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
413 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
414 /// If last line finished on vertex the lines creation sequence has to be break
415 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
416 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
417 if (aWidgets.last() == aPanel->activeWidget()) {
418 breakOperationSequence();
419 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aPanel->activeWidget());
420 PartSet_Tools::setConstraints(myCurrentSketch, aOperation->feature(),
421 SketchPlugin_Line::END_ID(), aPnt2dWgt->x(), aPnt2dWgt->y());
427 //void PartSet_Module::featureCreated(QAction* theFeature)
429 // connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
432 //std::string PartSet_Module::featureFile(const std::string& theFeatureId)
434 // return myFeaturesInFiles[theFeatureId];
440 //void PartSet_Module::onFeatureTriggered()
442 // QAction* aCmd = dynamic_cast<QAction*>(sender());
443 // //Do nothing on uncheck
444 // if (aCmd->isCheckable() && !aCmd->isChecked())
446 // launchOperation(aCmd->data().toString());
450 //void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
452 // XGUI_Workshop* aXWshp = xWorkshop();
453 // XGUI_Displayer* aDisplayer = aXWshp->displayer();
454 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
456 // XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
457 // connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
458 // SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
460 // //aDisplayer->deactivateObjectsOutOfContext();
461 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
463 // if (aSketchOp->isEditOperation()) {
464 // setSketchingMode(getSketchPlane(aSketchOp->feature()));
466 // aDisplayer->openLocalContext();
467 // aDisplayer->activateObjectsOutOfContext(QIntList());
468 // myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
469 // aDisplayer->addSelectionFilter(myPlaneFilter);
470 // QIntList aModes = sketchSelectionModes(aPreviewOp->feature());
471 // aDisplayer->setSelectionModes(aModes);
477 //void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
479 // if (!theOperation)
481 // XGUI_Workshop* aXWshp = xWorkshop();
482 // XGUI_Displayer* aDisplayer = aXWshp->displayer();
483 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
485 // XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
487 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
489 // aDisplayer->closeLocalContexts();
491 // PartSet_OperationFeatureCreate* aCreationOp =
492 // dynamic_cast<PartSet_OperationFeatureCreate*>(aPreviewOp);
493 // if (aCreationOp) {
494 // // Activate just created object for selection
495 // FeaturePtr aFeature = aCreationOp->feature();
496 // QIntList aModes = sketchSelectionModes(aFeature);
497 // const std::list<ResultPtr>& aResults = aFeature->results();
498 // std::list<ResultPtr>::const_iterator anIt, aLast = aResults.end();
499 // for (anIt = aResults.begin(); anIt != aLast; anIt++) {
500 // aDisplayer->activate(*anIt, aModes);
502 // aDisplayer->activate(aFeature, aModes);
503 // aDisplayer->clearSelected();
507 // // Activate results of current feature for selection
508 // //FeaturePtr aFeature = theOperation->feature();
509 // //XGUI_Displayer* aDisplayer = aXWshp->displayer();
510 // //std::list<ResultPtr> aResults = aFeature->results();
511 // //std::list<ResultPtr>::const_iterator aIt;
512 // //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
513 // // aDisplayer->activate(*aIt);
518 //void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
520 // QList<ObjectPtr> aFeatures = workshop()->selection()->selectedObjects();
521 // if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
522 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
524 // editFeature(aFeature);
528 //void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
530 // XGUI_Workshop* aXWshp = xWorkshop();
531 // PartSet_OperationSketchBase* aPreviewOp =
532 // dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
534 // ModuleBase_ISelection* aSelection = workshop()->selection();
535 // aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection);
539 //void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
541 // PartSet_OperationSketchBase* aPreviewOp =
542 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
544 // ModuleBase_ISelection* aSelection = workshop()->selection();
545 // // Initialise operation with preliminary selection
546 // aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection);
550 //void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
552 // PartSet_OperationSketchBase* aPreviewOp =
553 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
555 // aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer());
558 //void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
560 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
561 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
563 // aPreviewOp->keyReleased(theEvent->key());
567 //void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
569 // PartSet_OperationSketchBase* aPreviewOp =
570 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
571 // Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
572 // if (aPreviewOp && (!aView.IsNull())) {
573 // ModuleBase_ISelection* aSelection = workshop()->selection();
574 // // Initialise operation with preliminary selection
575 // aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection);
579 //void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
581 // myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
584 //void PartSet_Module::onSketchLaunched()
586 // xWorkshop()->actionsMgr()->update();
587 // // Set working plane
588 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
589 // FeaturePtr aSketch = anOperation->feature();
590 // setSketchingMode(getSketchPlane(aSketch));
593 //void PartSet_Module::onFitAllView()
595 // myWorkshop->viewer()->fitAll();
598 //void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject)
600 // FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
602 // std::string aKind = aFeature ? aFeature->getKind() : "";
603 // ModuleBase_Operation* anOperation = createOperation(theName, aKind);
605 // PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
607 // PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast<PartSet_OperationFeatureCreate*>(anOperation);
609 // aCreateOp->initFeature(aFeature);
611 // anOperation->setFeature(aFeature);
613 // ModuleBase_ISelection* aSelection = workshop()->selection();
614 // // Initialise operation with preliminary selection
615 // aSketchOp->initSelection(aSelection, myWorkshop->viewer());
616 // } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation
617 // anOperation->setFeature(aFeature);
618 // ////Deactivate result of current feature in order to avoid its selection
619 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
620 // std::list<ResultPtr> aResults = aFeature->results();
621 // std::list<ResultPtr>::const_iterator aIt;
622 // for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
623 // aDisplayer->deactivate(*aIt);
626 // sendOperation(anOperation);
627 // xWorkshop()->actionsMgr()->updateCheckState();
630 //void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
632 // ModuleBase_IViewer* aViewer = myWorkshop->viewer();
633 // aViewer->enableMultiselection(theEnabled);
636 //void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
638 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
640 // // foreach(ObjectPtr aObject, theFeatures) {
641 // // activateFeature(aObject);
644 // aDisplayer->stopSelection(theFeatures, isStop, false);
646 // ModuleBase_IViewer* aViewer = myWorkshop->viewer();
647 // aViewer->enableSelection(!isStop);
649 // aDisplayer->updateViewer();
652 //void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
654 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
655 // aDisplayer->setSelected(theFeatures, false);
656 // aDisplayer->updateViewer();
659 //void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
661 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
662 // if (!myPlaneFilter.IsNull()) {
663 // aDisplayer->removeSelectionFilter(myPlaneFilter);
664 // myPlaneFilter.Nullify();
667 // // Clear standard selection modes
668 // aDisplayer->setSelectionModes(aModes);
669 // aDisplayer->openLocalContext();
672 // mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
673 // aDisplayer->addSelectionFilter(mySketchFilter);
675 // // Get default selection modes
676 // aModes = sketchSelectionModes(ObjectPtr());
677 // aDisplayer->activateObjectsOutOfContext(aModes);
680 //void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
682 // bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
683 // ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
684 // PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
686 // std::list<FeaturePtr> aList = aPrevOp->subFeatures();
687 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
688 // QIntList aModes = sketchSelectionModes(aPrevOp->feature());
689 // std::list<FeaturePtr>::iterator aSFIt;
690 // for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
691 // std::list<ResultPtr> aResults = (*aSFIt)->results();
692 // std::list<ResultPtr>::iterator aIt;
693 // for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
695 // aDisplayer->erase((*aIt), false);
698 // aDisplayer->erase((*aSFIt), false);
700 // //aDisplayer->deactivateObjectsOutOfContext();
703 // ModelAPI_EventCreator::get()->sendUpdated(
704 // theFeature, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
707 //ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
708 // const std::string& theFeatureKind)
710 // // create the operation
711 // ModuleBase_Operation* anOperation = 0;
712 // if (theCmdId == PartSet_OperationSketch::Type()) {
713 // anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
715 // ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
716 // CompositeFeaturePtr aSketch;
717 // PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
719 // aSketch = aPrevOp->sketch();
721 // if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) {
722 // anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
723 // } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) {
724 // anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
728 // if (!anOperation) {
729 // anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
732 // // set operation description and list of widgets corresponding to the feature xml definition
733 // std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
735 // std::string aPluginFileName = featureFile(aFeatureKind);
736 // Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
737 // aWdgReader.readAll();
738 // std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
739 // std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
741 // anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
742 // anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
744 // // connect the operation
745 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
747 // connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this,
748 // SLOT(onFeatureConstructed(ObjectPtr, int)));
749 // connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
750 // SLOT(onRestartOperation(std::string, ObjectPtr)));
751 // // If manage multi selection the it will be impossible to select more then one
752 // // object under operation Edit
753 //// connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
754 //// SLOT(onMultiSelectionEnabled(bool)));
756 // connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
757 // SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
758 // connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
759 // SLOT(onSetSelection(const QList<ObjectPtr>&)));
761 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
763 // connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
764 // SLOT(onPlaneSelected(double, double, double)));
765 // connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
766 // connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched()));
770 // return anOperation;
774 //void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
776 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
780 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
784 // FeaturePtr aFeature = aPreviewOp->feature();
785 // if (!aFeature || aFeature->getKind() != theCmdId)
788 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
789 // // Hide result of sketch
790 // std::list<ResultPtr> aResults = aFeature->results();
791 // std::list<ResultPtr>::const_iterator aIt;
792 // for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt)
793 // aDisplayer->erase(*aIt, false);
795 // std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
797 // std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
798 // for (; anIt != aLast; anIt++) {
799 // std::shared_ptr<SketchPlugin_Feature> aSPFeature = std::dynamic_pointer_cast<
800 // SketchPlugin_Feature>(*anIt);
803 // std::list<ResultPtr> aResults = aSPFeature->results();
804 // std::list<ResultPtr>::const_iterator aRIt;
805 // for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
806 // aDisplayer->display((*aRIt), false);
807 // aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt)));
809 // aDisplayer->display(aSPFeature, false);
810 // aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature));
812 // aDisplayer->updateViewer();
815 //void PartSet_Module::editFeature(FeaturePtr theFeature)
820 // if (theFeature->getKind() == SKETCH_KIND) {
821 //FeaturePtr aFeature = theFeature;
822 //if (XGUI_Tools::isModelObject(aFeature)) {
823 // ObjectPtr aObject = std::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
824 // aFeature = aObject->featureRef();
828 // onRestartOperation(theFeature->getKind(), theFeature);
829 // updateCurrentPreview(theFeature->getKind());
834 //void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute)
836 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
838 // PartSet_OperationSketchBase* aPreviewOp =
839 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
843 // std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
844 // aFeature->data()->attribute(theAttribute));
846 // PartSet_Tools::setConstraints(aPreviewOp->sketch(), aFeature, theAttribute, aPoint->x(),
850 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
851 Config_WidgetAPI* theWidgetApi, std::string theParentId,
852 QList<ModuleBase_ModelWidget*>& theModelWidgets)
854 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
855 XGUI_Workshop* aWorkshop = aConnector->workshop();
856 if (theType == "sketch-start-label") {
857 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
858 aWgt->setWorkshop(aWorkshop);
859 theModelWidgets.append(aWgt);
860 return aWgt->getControl();
861 } else if (theType == "sketch-2dpoint_selector") {
862 PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
863 aWgt->setWorkshop(aWorkshop);
864 aWgt->setSketch(myCurrentSketch);
866 connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)),
867 this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
869 theModelWidgets.append(aWgt);
870 return aWgt->getControl();
871 } if (theType == "point2ddistance") {
872 PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
873 aWgt->setWorkshop(aWorkshop);
874 aWgt->setSketch(myCurrentSketch);
876 theModelWidgets.append(aWgt);
877 return aWgt->getControl();
883 //XGUI_Workshop* PartSet_Module::xWorkshop() const
885 // XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
887 // return aConnector->workshop();
893 //QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
896 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
898 // if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
899 // aModes.append(TopAbs_FACE);
901 // } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
902 // aModes.append(AIS_DSM_Text);
903 // aModes.append(AIS_DSM_Line);
907 // aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
908 // aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
913 //gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
915 // DataPtr aData = theSketch->data();
916 // std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
917 // aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
918 // std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
919 // aData->attribute(SketchPlugin_Sketch::NORM_ID()));
920 // gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
921 // gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
922 // return gp_Pln(aOrig, aDir);
926 //void PartSet_Module::onSelectionChanged()
928 // ModuleBase_ISelection* aSelect = myWorkshop->selection();
929 // QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
930 // // We need to stop edit operation if selection is cleared
931 // if (aSelected.size() == 0) {
932 // // do not perform commit of the current edit operation here, because
933 // // this functionality is realized inside this operation
934 // /*PartSet_OperationFeatureEdit* anEditOp =
935 // dynamic_cast<PartSet_OperationFeatureEdit*>(myWorkshop->currentOperation());
938 // anEditOp->commit();*/
940 // PartSet_OperationSketchBase* aSketchOp =
941 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
943 // aSketchOp->selectionChanged(aSelect);