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>
74 #include <QApplication>
76 #include <GeomAlgoAPI_FaceBuilder.h>
77 #include <GeomDataAPI_Dir.h>
84 /*!Create and return new instance of XGUI_Module*/
85 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
87 return new PartSet_Module(theWshop);
90 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
91 : ModuleBase_IModule(theWshop),
92 myIsDragging(false), myRestartingMode(true), myDragDone(false)
94 //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
95 ModuleBase_IViewer* aViewer = aViewer = theWshop->viewer();
96 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
97 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
99 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
100 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
102 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
103 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
105 //myListener = new PartSet_Listener(this);
107 // connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)),
108 // this, SLOT(onOperationStarted(ModuleBase_Operation*)));
110 // connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
111 // SLOT(onOperationStopped(ModuleBase_Operation*)));
113 //XGUI_Workshop* aXWshop = xWorkshop();
114 //XGUI_ContextMenuMgr* aContextMenuMgr = aXWshop->contextMenuMgr();
115 //connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
116 // SLOT(onContextMenuCommand(const QString&, bool)));
120 PartSet_Module::~PartSet_Module()
124 void PartSet_Module::registerValidators()
126 //Registering of validators
127 SessionPtr aMgr = ModelAPI_Session::get();
128 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
129 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
130 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
131 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
132 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
133 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
137 void PartSet_Module::onOperationComitted(ModuleBase_Operation* theOperation)
139 if (theOperation->isEditOperation())
141 /// Restart sketcher operations automatically
142 FeaturePtr aFeature = theOperation->feature();
143 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
144 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
145 if (aSPFeature && myRestartingMode) {
146 myLastOperationId = theOperation->id();
147 myLastFeature = theOperation->feature();
148 launchOperation(myLastOperationId);
150 breakOperationSequence();
154 void PartSet_Module::breakOperationSequence()
156 myLastOperationId = "";
157 myLastFeature = FeaturePtr();
158 myRestartingMode = false;
162 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
164 breakOperationSequence();
167 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
169 myRestartingMode = true;
170 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
171 // Display all sketcher sub-Objects
172 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
173 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
174 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
176 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
177 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
178 std::list<ResultPtr> aResults = aFeature->results();
179 std::list<ResultPtr>::const_iterator aIt;
180 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
181 aDisplayer->display((*aIt), false);
183 aDisplayer->display(aFeature);
185 // Hide sketcher result
186 std::list<ResultPtr> aResults = myCurrentSketch->results();
187 std::list<ResultPtr>::const_iterator aIt;
188 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
189 aDisplayer->erase((*aIt), false);
191 aDisplayer->erase(myCurrentSketch);
195 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
197 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
198 DataPtr aData = myCurrentSketch->data();
199 if ((!aData) || (!aData->isValid())) {
200 // The sketch was aborted
201 myCurrentSketch = CompositeFeaturePtr();
204 // Hide all sketcher sub-Objects
205 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
206 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
207 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
208 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
209 std::list<ResultPtr> aResults = aFeature->results();
210 std::list<ResultPtr>::const_iterator aIt;
211 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
212 aDisplayer->erase((*aIt), false);
214 aDisplayer->erase(aFeature, false);
216 // Display sketcher result
217 std::list<ResultPtr> aResults = myCurrentSketch->results();
218 std::list<ResultPtr>::const_iterator aIt;
219 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
220 aDisplayer->display((*aIt), false);
222 aDisplayer->display(myCurrentSketch);
224 myCurrentSketch = CompositeFeaturePtr();
230 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
232 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
233 ModuleBase_ModelWidget* aWgt = theOperation->propertyPanel()->activeWidget();
234 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
235 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
237 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
238 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
239 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
241 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
242 PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(),
243 aWgt->attributeID(), aPoint->x(), aPoint->y());
244 theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
252 void PartSet_Module::onSelectionChanged()
254 // Activate edit operation for sketcher objects
255 //ModuleBase_ISelection* aSelect = myWorkshop->selection();
256 //QObjectPtrList aObjects = aSelect->selectedPresentations();
257 //if (aObjects.size() == 1) {
258 // FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first());
260 // std::shared_ptr<SketchPlugin_Feature> aSPFeature =
261 // std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
263 // editFeature(aSPFeature);
269 //ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId)
271 // ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
273 // // If the current operation is sketcher sub-operation then we have to create
274 // // Costomized operation
275 // if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
276 // PartSet_Operation* aPSOp = new PartSet_Operation(theFeatureId.c_str(), this);
277 // aPSOp->setWorkshop(myWorkshop);
278 // connect(myWorkshop, SIGNAL(selectionChanged()), aPSOp, SLOT(onSelectionChanged()));
282 // return ModuleBase_IModule::getNewOperation(theFeatureId);
286 void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
288 if (!(theEvent->buttons() & Qt::LeftButton))
290 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
291 // Use only for sketch operations
292 if (aOperation && myCurrentSketch) {
293 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
296 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
297 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
299 // Avoid non-sketch operations
300 if ((!isSketchOpe) && (!isSketcher))
303 bool isEditing = aOperation->isEditOperation();
305 // Ignore creation sketch operation
306 if ((!isSketcher) && (!isEditing))
309 // Remember highlighted objects for editing
310 ModuleBase_ISelection* aSelect = myWorkshop->selection();
311 QList<ModuleBase_ViewerPrs> aObjects = aSelect->getHighlighted();
312 myEditingFeatures.clear();
313 if (aObjects.size() > 0) {
314 foreach(ModuleBase_ViewerPrs aPrs, aObjects) {
315 FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first().object());
317 myEditingFeatures.append(aFeature);
320 // If nothing highlighted - return
321 if (myEditingFeatures.size() == 0)
325 CompositeFeaturePtr aSketch =
326 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aOperation->feature());
327 if (!PartSet_Tools::sketchPlane(aSketch))
330 //myCurrentSketch = aOperation->feature();
332 get2dPoint(theWnd, theEvent, myCurX, myCurY);
334 myWorkshop->viewer()->enableSelection(false);
338 } else if (isSketchOpe && isEditing) {
342 get2dPoint(theWnd, theEvent, myCurX, myCurY);
344 myWorkshop->viewer()->enableSelection(false);
346 // This is necessary in order to finalize previous operation
347 QApplication::processEvents();
354 void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
355 double& theX, double& theY)
357 Handle(V3d_View) aView = theWnd->v3dView();
358 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
359 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
363 void PartSet_Module::launchEditing()
365 if (myEditingFeatures.size() == 1) {
366 FeaturePtr aFeature = myEditingFeatures.first();
367 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
368 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
370 editFeature(aSPFeature);
375 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
378 myIsDragging = false;
379 myWorkshop->viewer()->enableSelection(true);
381 myWorkshop->currentOperation()->commit();
386 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
389 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
390 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
391 return; // No edit operation activated
393 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
394 Handle(V3d_View) aView = theWnd->v3dView();
395 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
397 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
398 double dX = aX - myCurX;
399 double dY = aY - myCurY;
401 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
402 std::dynamic_pointer_cast<SketchPlugin_Feature>(aOperation->feature());
403 if (aSketchFeature) {
404 aSketchFeature->move(dX, dY);
405 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
406 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
407 }/* else { // Alternative case for moving
408 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
409 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
410 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
411 PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
413 aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
424 QStringList PartSet_Module::sketchOperationIdList() const
427 aIds << SketchPlugin_Line::ID().c_str();
428 aIds << SketchPlugin_Point::ID().c_str();
429 aIds << SketchPlugin_Arc::ID().c_str();
430 aIds << SketchPlugin_Circle::ID().c_str();
431 aIds << SketchPlugin_ConstraintLength::ID().c_str();
432 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
433 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
434 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
435 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
436 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
440 void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
442 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
443 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
444 /// If last line finished on vertex the lines creation sequence has to be break
445 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
446 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
447 if (aWidgets.last() == aPanel->activeWidget()) {
448 breakOperationSequence();
454 //void PartSet_Module::featureCreated(QAction* theFeature)
456 // connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
459 //std::string PartSet_Module::featureFile(const std::string& theFeatureId)
461 // return myFeaturesInFiles[theFeatureId];
467 //void PartSet_Module::onFeatureTriggered()
469 // QAction* aCmd = dynamic_cast<QAction*>(sender());
470 // //Do nothing on uncheck
471 // if (aCmd->isCheckable() && !aCmd->isChecked())
473 // launchOperation(aCmd->data().toString());
477 //void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
479 // XGUI_Workshop* aXWshp = xWorkshop();
480 // XGUI_Displayer* aDisplayer = aXWshp->displayer();
481 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
483 // XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
484 // connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
485 // SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
487 // //aDisplayer->deactivateObjectsOutOfContext();
488 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
490 // if (aSketchOp->isEditOperation()) {
491 // setSketchingMode(getSketchPlane(aSketchOp->feature()));
493 // aDisplayer->openLocalContext();
494 // aDisplayer->activateObjectsOutOfContext(QIntList());
495 // myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
496 // aDisplayer->addSelectionFilter(myPlaneFilter);
497 // QIntList aModes = sketchSelectionModes(aPreviewOp->feature());
498 // aDisplayer->setSelectionModes(aModes);
504 //void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
506 // if (!theOperation)
508 // XGUI_Workshop* aXWshp = xWorkshop();
509 // XGUI_Displayer* aDisplayer = aXWshp->displayer();
510 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
512 // XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
514 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
516 // aDisplayer->closeLocalContexts();
518 // PartSet_OperationFeatureCreate* aCreationOp =
519 // dynamic_cast<PartSet_OperationFeatureCreate*>(aPreviewOp);
520 // if (aCreationOp) {
521 // // Activate just created object for selection
522 // FeaturePtr aFeature = aCreationOp->feature();
523 // QIntList aModes = sketchSelectionModes(aFeature);
524 // const std::list<ResultPtr>& aResults = aFeature->results();
525 // std::list<ResultPtr>::const_iterator anIt, aLast = aResults.end();
526 // for (anIt = aResults.begin(); anIt != aLast; anIt++) {
527 // aDisplayer->activate(*anIt, aModes);
529 // aDisplayer->activate(aFeature, aModes);
530 // aDisplayer->clearSelected();
534 // // Activate results of current feature for selection
535 // //FeaturePtr aFeature = theOperation->feature();
536 // //XGUI_Displayer* aDisplayer = aXWshp->displayer();
537 // //std::list<ResultPtr> aResults = aFeature->results();
538 // //std::list<ResultPtr>::const_iterator aIt;
539 // //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
540 // // aDisplayer->activate(*aIt);
545 //void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
547 // QList<ObjectPtr> aFeatures = workshop()->selection()->selectedObjects();
548 // if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
549 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
551 // editFeature(aFeature);
555 //void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
557 // XGUI_Workshop* aXWshp = xWorkshop();
558 // PartSet_OperationSketchBase* aPreviewOp =
559 // dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
561 // ModuleBase_ISelection* aSelection = workshop()->selection();
562 // aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection);
566 //void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
568 // PartSet_OperationSketchBase* aPreviewOp =
569 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
571 // ModuleBase_ISelection* aSelection = workshop()->selection();
572 // // Initialise operation with preliminary selection
573 // aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection);
577 //void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
579 // PartSet_OperationSketchBase* aPreviewOp =
580 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
582 // aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer());
585 //void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
587 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
588 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
590 // aPreviewOp->keyReleased(theEvent->key());
594 //void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
596 // PartSet_OperationSketchBase* aPreviewOp =
597 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
598 // Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
599 // if (aPreviewOp && (!aView.IsNull())) {
600 // ModuleBase_ISelection* aSelection = workshop()->selection();
601 // // Initialise operation with preliminary selection
602 // aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection);
606 //void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
608 // myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
611 //void PartSet_Module::onSketchLaunched()
613 // xWorkshop()->actionsMgr()->update();
614 // // Set working plane
615 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
616 // FeaturePtr aSketch = anOperation->feature();
617 // setSketchingMode(getSketchPlane(aSketch));
620 //void PartSet_Module::onFitAllView()
622 // myWorkshop->viewer()->fitAll();
625 //void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject)
627 // FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
629 // std::string aKind = aFeature ? aFeature->getKind() : "";
630 // ModuleBase_Operation* anOperation = createOperation(theName, aKind);
632 // PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
634 // PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast<PartSet_OperationFeatureCreate*>(anOperation);
636 // aCreateOp->initFeature(aFeature);
638 // anOperation->setFeature(aFeature);
640 // ModuleBase_ISelection* aSelection = workshop()->selection();
641 // // Initialise operation with preliminary selection
642 // aSketchOp->initSelection(aSelection, myWorkshop->viewer());
643 // } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation
644 // anOperation->setFeature(aFeature);
645 // ////Deactivate result of current feature in order to avoid its selection
646 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
647 // std::list<ResultPtr> aResults = aFeature->results();
648 // std::list<ResultPtr>::const_iterator aIt;
649 // for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
650 // aDisplayer->deactivate(*aIt);
653 // sendOperation(anOperation);
654 // xWorkshop()->actionsMgr()->updateCheckState();
657 //void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
659 // ModuleBase_IViewer* aViewer = myWorkshop->viewer();
660 // aViewer->enableMultiselection(theEnabled);
663 //void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
665 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
667 // // foreach(ObjectPtr aObject, theFeatures) {
668 // // activateFeature(aObject);
671 // aDisplayer->stopSelection(theFeatures, isStop, false);
673 // ModuleBase_IViewer* aViewer = myWorkshop->viewer();
674 // aViewer->enableSelection(!isStop);
676 // aDisplayer->updateViewer();
679 //void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
681 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
682 // aDisplayer->setSelected(theFeatures, false);
683 // aDisplayer->updateViewer();
686 //void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
688 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
689 // if (!myPlaneFilter.IsNull()) {
690 // aDisplayer->removeSelectionFilter(myPlaneFilter);
691 // myPlaneFilter.Nullify();
694 // // Clear standard selection modes
695 // aDisplayer->setSelectionModes(aModes);
696 // aDisplayer->openLocalContext();
699 // mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
700 // aDisplayer->addSelectionFilter(mySketchFilter);
702 // // Get default selection modes
703 // aModes = sketchSelectionModes(ObjectPtr());
704 // aDisplayer->activateObjectsOutOfContext(aModes);
707 //void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
709 // bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
710 // ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
711 // PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
713 // std::list<FeaturePtr> aList = aPrevOp->subFeatures();
714 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
715 // QIntList aModes = sketchSelectionModes(aPrevOp->feature());
716 // std::list<FeaturePtr>::iterator aSFIt;
717 // for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
718 // std::list<ResultPtr> aResults = (*aSFIt)->results();
719 // std::list<ResultPtr>::iterator aIt;
720 // for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
722 // aDisplayer->erase((*aIt), false);
725 // aDisplayer->erase((*aSFIt), false);
727 // //aDisplayer->deactivateObjectsOutOfContext();
730 // ModelAPI_EventCreator::get()->sendUpdated(
731 // theFeature, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
734 //ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
735 // const std::string& theFeatureKind)
737 // // create the operation
738 // ModuleBase_Operation* anOperation = 0;
739 // if (theCmdId == PartSet_OperationSketch::Type()) {
740 // anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
742 // ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
743 // CompositeFeaturePtr aSketch;
744 // PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
746 // aSketch = aPrevOp->sketch();
748 // if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) {
749 // anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
750 // } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) {
751 // anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
755 // if (!anOperation) {
756 // anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
759 // // set operation description and list of widgets corresponding to the feature xml definition
760 // std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
762 // std::string aPluginFileName = featureFile(aFeatureKind);
763 // Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
764 // aWdgReader.readAll();
765 // std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
766 // std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
768 // anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
769 // anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
771 // // connect the operation
772 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
774 // connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this,
775 // SLOT(onFeatureConstructed(ObjectPtr, int)));
776 // connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
777 // SLOT(onRestartOperation(std::string, ObjectPtr)));
778 // // If manage multi selection the it will be impossible to select more then one
779 // // object under operation Edit
780 //// connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
781 //// SLOT(onMultiSelectionEnabled(bool)));
783 // connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
784 // SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
785 // connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
786 // SLOT(onSetSelection(const QList<ObjectPtr>&)));
788 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
790 // connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
791 // SLOT(onPlaneSelected(double, double, double)));
792 // connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
793 // connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched()));
797 // return anOperation;
801 //void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
803 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
807 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
811 // FeaturePtr aFeature = aPreviewOp->feature();
812 // if (!aFeature || aFeature->getKind() != theCmdId)
815 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
816 // // Hide result of sketch
817 // std::list<ResultPtr> aResults = aFeature->results();
818 // std::list<ResultPtr>::const_iterator aIt;
819 // for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt)
820 // aDisplayer->erase(*aIt, false);
822 // std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
824 // std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
825 // for (; anIt != aLast; anIt++) {
826 // std::shared_ptr<SketchPlugin_Feature> aSPFeature = std::dynamic_pointer_cast<
827 // SketchPlugin_Feature>(*anIt);
830 // std::list<ResultPtr> aResults = aSPFeature->results();
831 // std::list<ResultPtr>::const_iterator aRIt;
832 // for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
833 // aDisplayer->display((*aRIt), false);
834 // aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt)));
836 // aDisplayer->display(aSPFeature, false);
837 // aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature));
839 // aDisplayer->updateViewer();
842 //void PartSet_Module::editFeature(FeaturePtr theFeature)
847 // if (theFeature->getKind() == SKETCH_KIND) {
848 //FeaturePtr aFeature = theFeature;
849 //if (XGUI_Tools::isModelObject(aFeature)) {
850 // ObjectPtr aObject = std::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
851 // aFeature = aObject->featureRef();
855 // onRestartOperation(theFeature->getKind(), theFeature);
856 // updateCurrentPreview(theFeature->getKind());
861 //void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute)
863 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
865 // PartSet_OperationSketchBase* aPreviewOp =
866 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
870 // std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
871 // aFeature->data()->attribute(theAttribute));
873 // PartSet_Tools::setConstraints(aPreviewOp->sketch(), aFeature, theAttribute, aPoint->x(),
877 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
878 Config_WidgetAPI* theWidgetApi, std::string theParentId,
879 QList<ModuleBase_ModelWidget*>& theModelWidgets)
881 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
882 XGUI_Workshop* aWorkshop = aConnector->workshop();
883 if (theType == "sketch-start-label") {
884 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
885 aWgt->setWorkshop(aWorkshop);
886 theModelWidgets.append(aWgt);
887 return aWgt->getControl();
889 } else if (theType == "sketch-2dpoint_selector") {
890 PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
891 aWgt->setWorkshop(aWorkshop);
892 aWgt->setSketch(myCurrentSketch);
894 connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)),
895 this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
897 theModelWidgets.append(aWgt);
898 return aWgt->getControl();
900 } if (theType == "point2ddistance") {
901 PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
902 aWgt->setWorkshop(aWorkshop);
903 aWgt->setSketch(myCurrentSketch);
905 theModelWidgets.append(aWgt);
906 return aWgt->getControl();
908 } if (theType == "sketch_shape_selector") {
909 PartSet_WidgetShapeSelector* aWgt =
910 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
911 aWgt->setSketcher(myCurrentSketch);
913 theModelWidgets.append(aWgt);
914 return aWgt->getControl();
921 //XGUI_Workshop* PartSet_Module::xWorkshop() const
923 // XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
925 // return aConnector->workshop();
931 //QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
934 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
936 // if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
937 // aModes.append(TopAbs_FACE);
939 // } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
940 // aModes.append(AIS_DSM_Text);
941 // aModes.append(AIS_DSM_Line);
945 // aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
946 // aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
951 //gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
953 // DataPtr aData = theSketch->data();
954 // std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
955 // aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
956 // std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
957 // aData->attribute(SketchPlugin_Sketch::NORM_ID()));
958 // gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
959 // gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
960 // return gp_Pln(aOrig, aDir);
964 //void PartSet_Module::onSelectionChanged()
966 // ModuleBase_ISelection* aSelect = myWorkshop->selection();
967 // QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
968 // // We need to stop edit operation if selection is cleared
969 // if (aSelected.size() == 0) {
970 // // do not perform commit of the current edit operation here, because
971 // // this functionality is realized inside this operation
972 // /*PartSet_OperationFeatureEdit* anEditOp =
973 // dynamic_cast<PartSet_OperationFeatureEdit*>(myWorkshop->currentOperation());
976 // anEditOp->commit();*/
978 // PartSet_OperationSketchBase* aSketchOp =
979 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
981 // aSketchOp->selectionChanged(aSelect);