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 // Hide all sketcher sub-Objects
199 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
200 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
202 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
203 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
204 std::list<ResultPtr> aResults = aFeature->results();
205 std::list<ResultPtr>::const_iterator aIt;
206 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
207 aDisplayer->erase((*aIt), false);
209 aDisplayer->erase(aFeature, false);
211 // Display sketcher result
212 std::list<ResultPtr> aResults = myCurrentSketch->results();
213 std::list<ResultPtr>::const_iterator aIt;
214 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
215 aDisplayer->display((*aIt), false);
217 aDisplayer->display(myCurrentSketch);
219 myCurrentSketch = CompositeFeaturePtr();
225 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
227 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
228 ModuleBase_ModelWidget* aWgt = theOperation->propertyPanel()->activeWidget();
229 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
230 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
232 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
233 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
234 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
236 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
237 PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(),
238 SketchPlugin_Line::START_ID(), aPoint->x(), aPoint->y());
239 theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
247 void PartSet_Module::onSelectionChanged()
249 // Activate edit operation for sketcher objects
250 //ModuleBase_ISelection* aSelect = myWorkshop->selection();
251 //QObjectPtrList aObjects = aSelect->selectedPresentations();
252 //if (aObjects.size() == 1) {
253 // FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first());
255 // std::shared_ptr<SketchPlugin_Feature> aSPFeature =
256 // std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
258 // editFeature(aSPFeature);
264 //ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId)
266 // ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
268 // // If the current operation is sketcher sub-operation then we have to create
269 // // Costomized operation
270 // if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
271 // PartSet_Operation* aPSOp = new PartSet_Operation(theFeatureId.c_str(), this);
272 // aPSOp->setWorkshop(myWorkshop);
273 // connect(myWorkshop, SIGNAL(selectionChanged()), aPSOp, SLOT(onSelectionChanged()));
277 // return ModuleBase_IModule::getNewOperation(theFeatureId);
281 void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
283 if (!(theEvent->buttons() & Qt::LeftButton))
285 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
286 // Use only for sketch operations
287 if (aOperation && myCurrentSketch) {
288 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
291 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
292 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
294 // Avoid non-sketch operations
295 if ((!isSketchOpe) && (!isSketcher))
298 bool isEditing = aOperation->isEditOperation();
300 // Ignore creation sketch operation
301 if ((!isSketcher) && (!isEditing))
304 // Remember highlighted objects for editing
305 ModuleBase_ISelection* aSelect = myWorkshop->selection();
306 QList<ModuleBase_ViewerPrs> aObjects = aSelect->getHighlighted();
307 myEditingFeatures.clear();
308 if (aObjects.size() > 0) {
309 foreach(ModuleBase_ViewerPrs aPrs, aObjects) {
310 FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first().object());
312 myEditingFeatures.append(aFeature);
315 // If nothing highlighted - return
316 if (myEditingFeatures.size() == 0)
320 CompositeFeaturePtr aSketch =
321 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aOperation->feature());
322 if (!PartSet_Tools::sketchPlane(aSketch))
325 //myCurrentSketch = aOperation->feature();
327 get2dPoint(theWnd, theEvent, myCurX, myCurY);
329 myWorkshop->viewer()->enableSelection(false);
333 } else if (isSketchOpe && isEditing) {
337 get2dPoint(theWnd, theEvent, myCurX, myCurY);
339 myWorkshop->viewer()->enableSelection(false);
341 // This is necessary in order to finalize previous operation
342 QApplication::processEvents();
344 //QTimer::singleShot(10, this, SLOT(launchEditing()));
350 void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
351 double& theX, double& theY)
353 Handle(V3d_View) aView = theWnd->v3dView();
354 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
355 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
359 void PartSet_Module::launchEditing()
361 if (myEditingFeatures.size() == 1) {
362 FeaturePtr aFeature = myEditingFeatures.first();
363 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
364 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
366 editFeature(aSPFeature);
371 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
374 myIsDragging = false;
375 myWorkshop->viewer()->enableSelection(true);
377 myWorkshop->currentOperation()->commit();
382 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
385 Handle(V3d_View) aView = theWnd->v3dView();
386 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
388 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
389 double dX = myCurX - aX;
390 double dY = myCurY - aY;
392 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
393 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
394 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
395 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
396 PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
398 aWgt2d->setPoint(aWgt2d->x() - dX, aWgt2d->y() - dY);
408 QStringList PartSet_Module::sketchOperationIdList() const
411 aIds << SketchPlugin_Line::ID().c_str();
412 aIds << SketchPlugin_Point::ID().c_str();
413 aIds << SketchPlugin_Arc::ID().c_str();
414 aIds << SketchPlugin_Circle::ID().c_str();
415 aIds << SketchPlugin_ConstraintLength::ID().c_str();
416 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
417 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
418 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
419 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
420 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
424 void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
426 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
427 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
428 /// If last line finished on vertex the lines creation sequence has to be break
429 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
430 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
431 if (aWidgets.last() == aPanel->activeWidget()) {
432 breakOperationSequence();
433 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aPanel->activeWidget());
434 PartSet_Tools::setConstraints(myCurrentSketch, aOperation->feature(),
435 SketchPlugin_Line::END_ID(), aPnt2dWgt->x(), aPnt2dWgt->y());
441 //void PartSet_Module::featureCreated(QAction* theFeature)
443 // connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
446 //std::string PartSet_Module::featureFile(const std::string& theFeatureId)
448 // return myFeaturesInFiles[theFeatureId];
454 //void PartSet_Module::onFeatureTriggered()
456 // QAction* aCmd = dynamic_cast<QAction*>(sender());
457 // //Do nothing on uncheck
458 // if (aCmd->isCheckable() && !aCmd->isChecked())
460 // launchOperation(aCmd->data().toString());
464 //void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
466 // XGUI_Workshop* aXWshp = xWorkshop();
467 // XGUI_Displayer* aDisplayer = aXWshp->displayer();
468 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
470 // XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
471 // connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
472 // SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
474 // //aDisplayer->deactivateObjectsOutOfContext();
475 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
477 // if (aSketchOp->isEditOperation()) {
478 // setSketchingMode(getSketchPlane(aSketchOp->feature()));
480 // aDisplayer->openLocalContext();
481 // aDisplayer->activateObjectsOutOfContext(QIntList());
482 // myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
483 // aDisplayer->addSelectionFilter(myPlaneFilter);
484 // QIntList aModes = sketchSelectionModes(aPreviewOp->feature());
485 // aDisplayer->setSelectionModes(aModes);
491 //void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
493 // if (!theOperation)
495 // XGUI_Workshop* aXWshp = xWorkshop();
496 // XGUI_Displayer* aDisplayer = aXWshp->displayer();
497 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
499 // XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
501 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
503 // aDisplayer->closeLocalContexts();
505 // PartSet_OperationFeatureCreate* aCreationOp =
506 // dynamic_cast<PartSet_OperationFeatureCreate*>(aPreviewOp);
507 // if (aCreationOp) {
508 // // Activate just created object for selection
509 // FeaturePtr aFeature = aCreationOp->feature();
510 // QIntList aModes = sketchSelectionModes(aFeature);
511 // const std::list<ResultPtr>& aResults = aFeature->results();
512 // std::list<ResultPtr>::const_iterator anIt, aLast = aResults.end();
513 // for (anIt = aResults.begin(); anIt != aLast; anIt++) {
514 // aDisplayer->activate(*anIt, aModes);
516 // aDisplayer->activate(aFeature, aModes);
517 // aDisplayer->clearSelected();
521 // // Activate results of current feature for selection
522 // //FeaturePtr aFeature = theOperation->feature();
523 // //XGUI_Displayer* aDisplayer = aXWshp->displayer();
524 // //std::list<ResultPtr> aResults = aFeature->results();
525 // //std::list<ResultPtr>::const_iterator aIt;
526 // //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
527 // // aDisplayer->activate(*aIt);
532 //void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
534 // QList<ObjectPtr> aFeatures = workshop()->selection()->selectedObjects();
535 // if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
536 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
538 // editFeature(aFeature);
542 //void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
544 // XGUI_Workshop* aXWshp = xWorkshop();
545 // PartSet_OperationSketchBase* aPreviewOp =
546 // dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
548 // ModuleBase_ISelection* aSelection = workshop()->selection();
549 // aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection);
553 //void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
555 // PartSet_OperationSketchBase* aPreviewOp =
556 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
558 // ModuleBase_ISelection* aSelection = workshop()->selection();
559 // // Initialise operation with preliminary selection
560 // aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection);
564 //void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
566 // PartSet_OperationSketchBase* aPreviewOp =
567 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
569 // aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer());
572 //void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
574 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
575 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
577 // aPreviewOp->keyReleased(theEvent->key());
581 //void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
583 // PartSet_OperationSketchBase* aPreviewOp =
584 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
585 // Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
586 // if (aPreviewOp && (!aView.IsNull())) {
587 // ModuleBase_ISelection* aSelection = workshop()->selection();
588 // // Initialise operation with preliminary selection
589 // aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection);
593 //void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
595 // myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
598 //void PartSet_Module::onSketchLaunched()
600 // xWorkshop()->actionsMgr()->update();
601 // // Set working plane
602 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
603 // FeaturePtr aSketch = anOperation->feature();
604 // setSketchingMode(getSketchPlane(aSketch));
607 //void PartSet_Module::onFitAllView()
609 // myWorkshop->viewer()->fitAll();
612 //void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject)
614 // FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
616 // std::string aKind = aFeature ? aFeature->getKind() : "";
617 // ModuleBase_Operation* anOperation = createOperation(theName, aKind);
619 // PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
621 // PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast<PartSet_OperationFeatureCreate*>(anOperation);
623 // aCreateOp->initFeature(aFeature);
625 // anOperation->setFeature(aFeature);
627 // ModuleBase_ISelection* aSelection = workshop()->selection();
628 // // Initialise operation with preliminary selection
629 // aSketchOp->initSelection(aSelection, myWorkshop->viewer());
630 // } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation
631 // anOperation->setFeature(aFeature);
632 // ////Deactivate result of current feature in order to avoid its selection
633 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
634 // std::list<ResultPtr> aResults = aFeature->results();
635 // std::list<ResultPtr>::const_iterator aIt;
636 // for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
637 // aDisplayer->deactivate(*aIt);
640 // sendOperation(anOperation);
641 // xWorkshop()->actionsMgr()->updateCheckState();
644 //void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
646 // ModuleBase_IViewer* aViewer = myWorkshop->viewer();
647 // aViewer->enableMultiselection(theEnabled);
650 //void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
652 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
654 // // foreach(ObjectPtr aObject, theFeatures) {
655 // // activateFeature(aObject);
658 // aDisplayer->stopSelection(theFeatures, isStop, false);
660 // ModuleBase_IViewer* aViewer = myWorkshop->viewer();
661 // aViewer->enableSelection(!isStop);
663 // aDisplayer->updateViewer();
666 //void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
668 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
669 // aDisplayer->setSelected(theFeatures, false);
670 // aDisplayer->updateViewer();
673 //void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
675 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
676 // if (!myPlaneFilter.IsNull()) {
677 // aDisplayer->removeSelectionFilter(myPlaneFilter);
678 // myPlaneFilter.Nullify();
681 // // Clear standard selection modes
682 // aDisplayer->setSelectionModes(aModes);
683 // aDisplayer->openLocalContext();
686 // mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
687 // aDisplayer->addSelectionFilter(mySketchFilter);
689 // // Get default selection modes
690 // aModes = sketchSelectionModes(ObjectPtr());
691 // aDisplayer->activateObjectsOutOfContext(aModes);
694 //void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
696 // bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
697 // ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
698 // PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
700 // std::list<FeaturePtr> aList = aPrevOp->subFeatures();
701 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
702 // QIntList aModes = sketchSelectionModes(aPrevOp->feature());
703 // std::list<FeaturePtr>::iterator aSFIt;
704 // for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
705 // std::list<ResultPtr> aResults = (*aSFIt)->results();
706 // std::list<ResultPtr>::iterator aIt;
707 // for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
709 // aDisplayer->erase((*aIt), false);
712 // aDisplayer->erase((*aSFIt), false);
714 // //aDisplayer->deactivateObjectsOutOfContext();
717 // ModelAPI_EventCreator::get()->sendUpdated(
718 // theFeature, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
721 //ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
722 // const std::string& theFeatureKind)
724 // // create the operation
725 // ModuleBase_Operation* anOperation = 0;
726 // if (theCmdId == PartSet_OperationSketch::Type()) {
727 // anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
729 // ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
730 // CompositeFeaturePtr aSketch;
731 // PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
733 // aSketch = aPrevOp->sketch();
735 // if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) {
736 // anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
737 // } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) {
738 // anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
742 // if (!anOperation) {
743 // anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
746 // // set operation description and list of widgets corresponding to the feature xml definition
747 // std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
749 // std::string aPluginFileName = featureFile(aFeatureKind);
750 // Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
751 // aWdgReader.readAll();
752 // std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
753 // std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
755 // anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
756 // anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
758 // // connect the operation
759 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
761 // connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this,
762 // SLOT(onFeatureConstructed(ObjectPtr, int)));
763 // connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
764 // SLOT(onRestartOperation(std::string, ObjectPtr)));
765 // // If manage multi selection the it will be impossible to select more then one
766 // // object under operation Edit
767 //// connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
768 //// SLOT(onMultiSelectionEnabled(bool)));
770 // connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
771 // SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
772 // connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
773 // SLOT(onSetSelection(const QList<ObjectPtr>&)));
775 // PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
777 // connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
778 // SLOT(onPlaneSelected(double, double, double)));
779 // connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
780 // connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched()));
784 // return anOperation;
788 //void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
790 // ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
794 // PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
798 // FeaturePtr aFeature = aPreviewOp->feature();
799 // if (!aFeature || aFeature->getKind() != theCmdId)
802 // XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
803 // // Hide result of sketch
804 // std::list<ResultPtr> aResults = aFeature->results();
805 // std::list<ResultPtr>::const_iterator aIt;
806 // for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt)
807 // aDisplayer->erase(*aIt, false);
809 // std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
811 // std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
812 // for (; anIt != aLast; anIt++) {
813 // std::shared_ptr<SketchPlugin_Feature> aSPFeature = std::dynamic_pointer_cast<
814 // SketchPlugin_Feature>(*anIt);
817 // std::list<ResultPtr> aResults = aSPFeature->results();
818 // std::list<ResultPtr>::const_iterator aRIt;
819 // for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
820 // aDisplayer->display((*aRIt), false);
821 // aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt)));
823 // aDisplayer->display(aSPFeature, false);
824 // aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature));
826 // aDisplayer->updateViewer();
829 //void PartSet_Module::editFeature(FeaturePtr theFeature)
834 // if (theFeature->getKind() == SKETCH_KIND) {
835 //FeaturePtr aFeature = theFeature;
836 //if (XGUI_Tools::isModelObject(aFeature)) {
837 // ObjectPtr aObject = std::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
838 // aFeature = aObject->featureRef();
842 // onRestartOperation(theFeature->getKind(), theFeature);
843 // updateCurrentPreview(theFeature->getKind());
848 //void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute)
850 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
852 // PartSet_OperationSketchBase* aPreviewOp =
853 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
857 // std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
858 // aFeature->data()->attribute(theAttribute));
860 // PartSet_Tools::setConstraints(aPreviewOp->sketch(), aFeature, theAttribute, aPoint->x(),
864 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
865 Config_WidgetAPI* theWidgetApi, std::string theParentId,
866 QList<ModuleBase_ModelWidget*>& theModelWidgets)
868 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
869 XGUI_Workshop* aWorkshop = aConnector->workshop();
870 if (theType == "sketch-start-label") {
871 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
872 aWgt->setWorkshop(aWorkshop);
873 theModelWidgets.append(aWgt);
874 return aWgt->getControl();
876 } else if (theType == "sketch-2dpoint_selector") {
877 PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
878 aWgt->setWorkshop(aWorkshop);
879 aWgt->setSketch(myCurrentSketch);
881 connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)),
882 this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
884 theModelWidgets.append(aWgt);
885 return aWgt->getControl();
887 } if (theType == "point2ddistance") {
888 PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
889 aWgt->setWorkshop(aWorkshop);
890 aWgt->setSketch(myCurrentSketch);
892 theModelWidgets.append(aWgt);
893 return aWgt->getControl();
895 } if (theType == "sketch_shape_selector") {
896 PartSet_WidgetShapeSelector* aWgt =
897 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
898 aWgt->setSketcher(myCurrentSketch);
900 theModelWidgets.append(aWgt);
901 return aWgt->getControl();
908 //XGUI_Workshop* PartSet_Module::xWorkshop() const
910 // XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
912 // return aConnector->workshop();
918 //QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
921 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
923 // if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
924 // aModes.append(TopAbs_FACE);
926 // } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
927 // aModes.append(AIS_DSM_Text);
928 // aModes.append(AIS_DSM_Line);
932 // aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
933 // aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
938 //gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
940 // DataPtr aData = theSketch->data();
941 // std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
942 // aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
943 // std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
944 // aData->attribute(SketchPlugin_Sketch::NORM_ID()));
945 // gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
946 // gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
947 // return gp_Pln(aOrig, aDir);
951 //void PartSet_Module::onSelectionChanged()
953 // ModuleBase_ISelection* aSelect = myWorkshop->selection();
954 // QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
955 // // We need to stop edit operation if selection is cleared
956 // if (aSelected.size() == 0) {
957 // // do not perform commit of the current edit operation here, because
958 // // this functionality is realized inside this operation
959 // /*PartSet_OperationFeatureEdit* anEditOp =
960 // dynamic_cast<PartSet_OperationFeatureEdit*>(myWorkshop->currentOperation());
963 // anEditOp->commit();*/
965 // PartSet_OperationSketchBase* aSketchOp =
966 // dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
968 // aSketchOp->selectionChanged(aSelect);