1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_Module.h"
4 #include "PartSet_WidgetSketchLabel.h"
5 #include "PartSet_Validators.h"
6 #include "PartSet_Tools.h"
7 #include "PartSet_WidgetPoint2d.h"
8 #include "PartSet_WidgetPoint2dDistance.h"
9 #include "PartSet_WidgetPoint2DFlyout.h"
10 #include "PartSet_WidgetShapeSelector.h"
11 #include "PartSet_WidgetPoint2dAngle.h"
12 #include "PartSet_WidgetMultiSelector.h"
13 #include "PartSet_WidgetEditor.h"
14 #include "PartSet_WidgetFileSelector.h"
15 #include "PartSet_WidgetSketchCreator.h"
16 #include "PartSet_SketcherMgr.h"
17 #include "PartSet_SketcherReetntrantMgr.h"
18 #include "PartSet_MenuMgr.h"
19 #include "PartSet_CustomPrs.h"
20 #include "PartSet_IconFactory.h"
21 #include "PartSet_WidgetChoice.h"
23 #include "PartSet_Filters.h"
24 #include "PartSet_FilterInfinite.h"
26 #include <PartSetPlugin_Remove.h>
27 #include <PartSetPlugin_Part.h>
28 #include <PartSetPlugin_Duplicate.h>
30 #include <ModuleBase_Operation.h>
31 #include <ModuleBase_OperationAction.h>
32 #include <ModuleBase_IViewer.h>
33 #include <ModuleBase_IViewWindow.h>
34 #include <ModuleBase_IPropertyPanel.h>
35 #include <ModuleBase_WidgetEditor.h>
36 #include <ModuleBase_WidgetValidated.h>
37 #include <ModuleBase_FilterFactory.h>
38 #include <ModuleBase_Tools.h>
39 #include <ModuleBase_OperationFeature.h>
41 #include <ModelAPI_Object.h>
42 #include <ModelAPI_Events.h>
43 #include <ModelAPI_Validator.h>
44 #include <ModelAPI_Data.h>
45 #include <ModelAPI_Session.h>
46 #include <ModelAPI_ResultBody.h>
47 #include <ModelAPI_AttributeString.h>
49 #include <GeomDataAPI_Point2D.h>
50 #include <GeomDataAPI_Point.h>
51 #include <GeomDataAPI_Dir.h>
53 #include <XGUI_Displayer.h>
54 #include <XGUI_Workshop.h>
55 #include <XGUI_OperationMgr.h>
56 #include <XGUI_PropertyPanel.h>
57 #include <XGUI_ModuleConnector.h>
58 #include <XGUI_ContextMenuMgr.h>
59 #include <XGUI_Tools.h>
60 #include <XGUI_ObjectsBrowser.h>
61 #include <XGUI_SelectionMgr.h>
62 #include <XGUI_DataModel.h>
63 #include <XGUI_ErrorMgr.h>
65 #include <SketchPlugin_Feature.h>
66 #include <SketchPlugin_Sketch.h>
67 #include <SketchPlugin_ConstraintAngle.h>
68 #include <SketchPlugin_ConstraintLength.h>
69 #include <SketchPlugin_ConstraintDistance.h>
70 #include <SketchPlugin_ConstraintParallel.h>
71 #include <SketchPlugin_ConstraintPerpendicular.h>
72 #include <SketchPlugin_ConstraintRadius.h>
74 #include <SketcherPrs_SymbolPrs.h>
75 #include <SketcherPrs_Tools.h>
77 #include <Events_Loop.h>
78 #include <Config_PropManager.h>
79 #include <Config_Keywords.h>
81 #include <StdSelect_TypeOfFace.hxx>
82 #include <TopoDS_Vertex.hxx>
84 #include <TopoDS_Shape.hxx>
85 #include <BRep_Tool.hxx>
86 #include <AIS_Dimension.hxx>
89 #include <QMouseEvent>
92 #include <QApplication>
93 #include <QMessageBox>
94 #include <QMainWindow>
97 #include <GeomAlgoAPI_FaceBuilder.h>
98 #include <GeomDataAPI_Dir.h>
100 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
106 /*!Create and return new instance of XGUI_Module*/
107 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
109 return new PartSet_Module(theWshop);
112 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
113 : ModuleBase_IModule(theWshop),
114 myVisualLayerId(0), myHasConstraintShown(true)
116 new PartSet_IconFactory();
118 mySketchMgr = new PartSet_SketcherMgr(this);
119 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
121 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
122 XGUI_Workshop* aWorkshop = aConnector->workshop();
124 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
125 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
126 this, SLOT(onOperationActivatedByPreselection()));
128 ModuleBase_IViewer* aViewer = theWshop->viewer();
129 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
130 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
131 connect(aViewer, SIGNAL(viewTransformed(int)),
132 SLOT(onViewTransformed(int)));
133 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
134 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
136 myMenuMgr = new PartSet_MenuMgr(this);
137 myCustomPrs = new PartSet_CustomPrs(theWshop);
139 Events_Loop* aLoop = Events_Loop::loop();
140 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
142 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
143 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
146 PartSet_Module::~PartSet_Module()
148 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
149 for (; aIt.More(); aIt.Next()) {
150 Handle(SelectMgr_Filter) aFilter = aIt.Value();
151 if (!aFilter.IsNull())
157 void PartSet_Module::activateSelectionFilters()
159 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
160 for (; aIt.More(); aIt.Next()) {
161 Handle(SelectMgr_Filter) aFilter = aIt.Value();
162 if (!aFilter.IsNull())
163 myWorkshop->viewer()->addSelectionFilter(aFilter);
167 void PartSet_Module::deactivateSelectionFilters()
169 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
170 for (; aIt.More(); aIt.Next()) {
171 Handle(SelectMgr_Filter) aFilter = aIt.Value();
172 if (!aFilter.IsNull())
173 myWorkshop->viewer()->removeSelectionFilter(aFilter);
177 void PartSet_Module::registerValidators()
179 //Registering of validators
180 SessionPtr aMgr = ModelAPI_Session::get();
181 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
182 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
183 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
184 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
185 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
186 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
187 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
188 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
189 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
190 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
191 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
192 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
193 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
194 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
195 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
196 aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator);
199 void PartSet_Module::registerFilters()
201 //Registering of selection filters
202 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
203 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
206 void PartSet_Module::registerProperties()
208 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
210 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
211 Config_Prop::Integer, SKETCH_WIDTH);
212 Config_PropManager::registerProp("Sketch planes", "rotate_to_plane", "Rotate to plane when selected",
213 Config_Prop::Boolean, "false");
216 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
218 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
221 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
223 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
224 mySketchMgr->commitNestedSketch(theOperation);
227 /// Restart sketcher operations automatically
228 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
230 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
231 if (aFOperation && !aFOperation->isEditOperation()) {
232 // the selection is cleared after commit the create operation
233 // in order to do not use the same selected objects in the restarted operation
234 // for common behaviour, the selection is cleared even if the operation is not restarted
235 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
236 XGUI_Workshop* aWorkshop = aConnector->workshop();
237 aWorkshop->selector()->clearSelection();
242 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
244 /// Restart sketcher operations automatically
245 mySketchReentrantMgr->operationAborted(theOperation);
248 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
250 /// Restart sketcher operations automatically
251 mySketchReentrantMgr->operationStarted(theOperation);
253 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
254 mySketchMgr->startSketch(theOperation);
256 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
257 mySketchMgr->startNestedSketch(theOperation);
260 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
262 myCustomPrs->activate(aFOperation->feature(), true);
265 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
267 ModuleBase_IModule::operationResumed(theOperation);
269 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
271 myCustomPrs->activate(aFOperation->feature(), true);
274 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
276 bool isModified = myCustomPrs->deactivate(false);
278 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
279 mySketchMgr->stopNestedSketch(theOperation);
282 //VSV: Viewer is updated on feature update and redisplay
284 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
285 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
286 aDisplayer->updateViewer();
288 mySketchMgr->onShowConstraintsToggle(myHasConstraintShown);
291 ModuleBase_Operation* PartSet_Module::currentOperation() const
293 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
294 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
295 return anOpMgr->currentOperation();
298 bool PartSet_Module::canUndo() const
300 bool aCanUndo = false;
301 SessionPtr aMgr = ModelAPI_Session::get();
302 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
303 aCanUndo = !aMgr->isOperation();
304 if (!aCanUndo) // check the enable state additionally by sketch manager
305 aCanUndo = aMgr->canUndo();
310 bool PartSet_Module::canRedo() const
312 bool aCanRedo = false;
313 SessionPtr aMgr = ModelAPI_Session::get();
314 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
315 aCanRedo = !aMgr->isOperation();
316 if (!aCanRedo) // check the enable state additionally by sketch manager
317 aCanRedo = aMgr->canRedo();
322 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
325 if (theActionId == "DELETE_CMD" || theActionId == "MOVE_CMD") {
326 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
328 // part features are removed in the PartSet module only.
329 if (aFeature->getKind() == PartSetPlugin_Part::ID())
336 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
338 // the sketch manager put the restriction to the objects erase
339 return mySketchMgr->canEraseObject(theObject);
342 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
344 // the sketch manager put the restriction to the objects display
345 return mySketchMgr->canDisplayObject(theObject);
348 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
350 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
352 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
353 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
354 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
355 if (isSketchOp || isNestedOp) {
356 // in active sketch operation it is possible to activate operation object in selection
357 // in the edit operation, e.g. points of the line can be moved when the line is edited
358 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
359 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
364 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
366 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
369 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
371 myMenuMgr->updateViewerMenu(theStdActions);
374 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
376 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
377 if (anError.isEmpty())
378 anError = sketchMgr()->getFeatureError(theFeature);
383 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
384 QStringList& theIds) const
386 myMenuMgr->grantedOperationIds(theOperation, theIds);
388 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
389 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
390 XGUI_Workshop* aWorkshop = aConnector->workshop();
392 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
396 void PartSet_Module::activeSelectionModes(QIntList& theModes)
399 if (mySketchMgr->activeSketch().get())
400 PartSet_SketcherMgr::sketchSelectionModes(theModes);
403 bool PartSet_Module::isMouseOverWindow()
405 return mySketchMgr->isMouseOverWindow();
408 void PartSet_Module::closeDocument()
413 void PartSet_Module::clearViewer()
415 myCustomPrs->clearPrs();
417 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
418 XGUI_Workshop* aWorkshop = aConnector->workshop();
419 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
420 aDisplayer->deactivateSelectionFilters();
423 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
425 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
429 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
430 // we have to manually activate the sketch label in edit mode
431 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
432 aPanel->activateWidget(aPanel->modelWidgets().first());
436 void PartSet_Module::onSelectionChanged()
438 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
442 bool isSketcherOp = false;
443 // An edit operation is enable only if the current opeation is the sketch operation
444 if (mySketchMgr->activeSketch()) {
445 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
446 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
449 // Editing of constraints can be done on selection
450 ModuleBase_ISelection* aSelect = myWorkshop->selection();
451 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
452 if (aSelected.size() == 1) {
453 ModuleBase_ViewerPrs aPrs = aSelected.first();
454 ObjectPtr aObject = aPrs.object();
455 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
457 std::string aId = aFeature->getKind();
458 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
459 (aId == SketchPlugin_ConstraintLength::ID()) ||
460 (aId == SketchPlugin_ConstraintDistance::ID()) ||
461 (aId == SketchPlugin_ConstraintAngle::ID())) {
462 editFeature(aFeature);
469 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
471 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
472 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
473 anOpMgr->onKeyReleased(theEvent);
476 #include <XGUI_SalomeConnector.h>
477 void PartSet_Module::onOperationActivatedByPreselection()
479 if (!mySketchReentrantMgr->canBeCommittedByPreselection())
482 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
483 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
484 // Set final definitions if they are necessary
485 //propertyPanelDefined(aOperation);
486 /// Commit sketcher operations automatically
487 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
490 if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
491 // Activate dimension value editing on double click
492 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
493 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
494 // Find corresponded widget to activate value editing
495 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
496 if (aWgt->attributeID() == "ConstraintValue") {
497 FeaturePtr aFeature = aFOperation->feature();
498 // the featue should be displayed in order to find the AIS text position,
499 // the place where the editor will be shown
500 aFeature->setDisplayed(true);
501 /// the execute is necessary to perform in the feature compute for flyout position
504 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
505 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
507 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
510 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
511 XGUI_Workshop* aWorkshop = aConnector->workshop();
512 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
513 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
514 Handle(AIS_InteractiveObject) anAISIO;
515 if (anAIS.get() != NULL) {
516 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
518 if (anAIS.get() != NULL) {
519 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
521 if (!anAISIO.IsNull()) {
522 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
523 if (!aDim.IsNull()) {
524 gp_Pnt aPosition = aDim->GetTextPosition();
526 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
527 Handle(V3d_View) aView = aViewer->activeView();
529 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
531 QWidget* aViewPort = aViewer->activeViewPort();
532 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
537 anEditor->setCursorPosition(aX, anY);
538 anEditor->showPopupEditor(false);
545 anOperation->commit();
549 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
550 Config_WidgetAPI* theWidgetApi, std::string theParentId)
552 ModuleBase_IWorkshop* aWorkshop = workshop();
553 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
554 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
555 ModuleBase_ModelWidget* aWgt = NULL;
556 if (theType == "sketch-start-label") {
557 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
558 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
559 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
560 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
561 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
562 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
564 } else if (theType == "sketch-2dpoint_selector") {
565 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
566 theWidgetApi, theParentId);
567 aPointWgt->setSketch(mySketchMgr->activeSketch());
568 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
570 }else if (theType == "sketch-2dpoint_flyout_selector") {
571 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
572 theWidgetApi, theParentId);
573 aPointWgt->setSketch(mySketchMgr->activeSketch());
574 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
576 } else if (theType == "point2ddistance") {
577 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
578 aWorkshop, theWidgetApi, theParentId);
579 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
581 } else if(theType == "point2dangle") {
582 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
583 aWorkshop, theWidgetApi, theParentId);
584 anAngleWgt->setSketch(mySketchMgr->activeSketch());
586 } else if (theType == "sketch_shape_selector") {
587 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
588 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
589 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
590 aWgt = aShapeSelectorWgt;
591 } else if (theType == "sketch_multi_selector") {
592 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
593 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
594 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
595 aWgt = aShapeSelectorWgt;
596 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
597 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
598 } else if (theType == "export_file_selector") {
599 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
600 } else if (theType == "sketch_launcher") {
601 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
602 } else if (theType == "module_choice") {
603 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi, theParentId);
604 connect(aWgt, SIGNAL(itemSelected(int)), SLOT(onBooleanOperationChange(int)));
609 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
611 ModuleBase_ModelWidget* anActiveWidget = 0;
613 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
614 if (!anActiveWidget) {
615 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
617 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
618 anActiveWidget = aPanel->activeWidget();
621 return anActiveWidget;
624 bool PartSet_Module::deleteObjects()
626 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
627 XGUI_Workshop* aWorkshop = aConnector->workshop();
628 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
630 //SessionPtr aMgr = ModelAPI_Session::get();
631 // 1. check whether the delete should be processed in the module
632 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
633 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
634 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
635 if (isSketchOp || isNestedOp) {
636 // 2. find selected presentations
637 // selected objects should be collected before the current operation abort because
638 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
639 ModuleBase_ISelection* aSel = workshop()->selection();
640 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
641 // if there are no selected objects in the viewer, that means that the selection in another
642 // place cased this method. It is necessary to return the false value to understande in above
643 // method that delete is not processed
644 if (aSelectedObj.count() == 0)
647 // avoid delete of the objects, which are not belong to the current sketch
648 // in order to do not delete results of other sketches
649 QObjectPtrList aSketchObjects;
650 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
651 for ( ; anIt != aLast; anIt++) {
652 ObjectPtr anObject = *anIt;
653 if (mySketchMgr->isObjectOfSketch(anObject)) {
654 // sketch feature should be used in this list because workshop deletes features only
655 // results are skipped
656 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
657 aSketchObjects.append(aSketchFeature);
660 // if the selection contains only local selected presentations from other sketches,
661 // the Delete operation should not be done at all
662 if (aSketchObjects.size() == 0)
665 // 3. start operation
666 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
667 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
669 // the active nested sketch operation should be aborted unconditionally
670 // the Delete action should be additionally granted for the Sketch operation
671 // in order to do not abort/commit it
672 if (!anOpMgr->canStartOperation(anOpAction->id()))
673 return true; // the objects are processed but can not be deleted
675 anOpMgr->startOperation(anOpAction);
677 // 4. delete features
678 // sketch feature should be skipped, only sub-features can be removed
679 // when sketch operation is active
680 aWorkshop->deleteFeatures(aSketchObjects);
682 anOpMgr->commitOperation();
685 bool isPartRemoved = false;
686 // Delete part with help of PartSet plugin
687 // TODO: the deleted objects has to be processed by multiselection
688 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
689 if (aObjects.size() == 1) {
690 ObjectPtr aObj = aObjects.first();
691 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
692 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
693 // Remove feature should be created in the document of the part results
694 ResultPtr aPartResult = aFeature->firstResult();
695 if (aPartResult.get()) {
696 std::shared_ptr<ModelAPI_ResultPart> aPart =
697 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
698 DocumentPtr aPartDoc = aPart->partDoc();
699 if (aPartDoc.get()) {
700 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
701 (PartSetPlugin_Remove::ID().c_str(), this);
702 if (!anOpMgr->canStartOperation(anOpAction->id()))
703 return true; // the objects are processed but can not be deleted
705 anOpMgr->startOperation(anOpAction);
707 FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
710 anOpMgr->commitOperation();
711 isPartRemoved = true;
716 return isPartRemoved;
721 void PartSet_Module::onFeatureTriggered()
723 QAction* aCmd = dynamic_cast<QAction*>(sender());
724 if (aCmd->isCheckable() && aCmd->isChecked()) {
725 // 1. check whether the delete should be processed in the module
726 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
727 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
729 // in case if in the viewer nothing is displayed, the create operation should not be
730 // comitted even if all values of the feature are initialized
731 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
732 // the action information should be saved before the operation is aborted
733 // because this abort leads to update command status, which unchecks this action
734 anOperation->abort();
735 launchOperation(aCmd->data().toString());
739 ModuleBase_IModule::onFeatureTriggered();
742 void PartSet_Module::launchOperation(const QString& theCmdId)
744 if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
745 // Show constraints if a constraint was anOperation
746 myHasConstraintShown = mySketchMgr->isConstraintsShown();
747 mySketchMgr->onShowConstraintsToggle(true);
749 ModuleBase_IModule::launchOperation(theCmdId);
753 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
755 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
756 if (!anAIS.IsNull()) {
757 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
758 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
759 if (!aDim.IsNull()) {
760 aCtx->SetZLayer(aDim, myVisualLayerId);
762 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
764 aCtx->SetZLayer(aCons, myVisualLayerId);
769 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
772 // it should be recomputed in order to disappear in the viewer if the corresponded object
774 //if (myCustomPrs->isActive())
775 // myCustomPrs->redisplay(theObject, false);
778 void PartSet_Module::onViewTransformed(int theTrsfType)
780 // Set length of arrows constant in pixel size
781 // if the operation is panning or rotate or panglobal then do nothing
782 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
784 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
785 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
786 if (aContext.IsNull())
789 //Handle(V3d_View) aView = aViewer->activeView();
791 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
792 XGUI_Workshop* aWorkshop = aConnector->workshop();
793 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
794 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
795 Handle(V3d_View) aView;
797 for (aV3dViewer->InitDefinedViews();
798 aV3dViewer->MoreDefinedViews();
799 aV3dViewer->NextDefinedViews()) {
800 Handle(V3d_View) aV = aV3dViewer->DefinedView();
801 double aS = aV->Scale();
809 double aLen = aView->Convert(20);
811 double aPrevLen = SketcherPrs_Tools::getArrowSize();
812 SketcherPrs_Tools::setArrowSize(aLen);
813 const double aPrevScale = aViewer->Scale(aViewer->activeView());
814 const double aCurScale = aViewer->activeView()->Camera()->Scale();
815 aViewer->SetScale(aViewer->activeView(), aCurScale);
816 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
817 bool isModified = false;
818 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
819 foreach (AISObjectPtr aAIS, aPrsList) {
820 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
822 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
823 if (!aDim.IsNull()) {
824 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
825 aContext->Redisplay(aDim, false);
830 aDisplayer->updateViewer();
833 bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
835 bool isRedisplayed = false;
836 if (myCustomPrs->isActive())
837 isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
839 return isRedisplayed;
842 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
844 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
846 QLabel* aLabel = aOB->activeDocLabel();
847 aLabel->installEventFilter(myMenuMgr);
848 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
849 SLOT(onActiveDocPopup(const QPoint&)));
850 //QPalette aPalet = aLabel->palette();
851 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
852 //aLabel->setPalette(aPalet);
853 aOB->treeView()->setExpandsOnDoubleClick(false);
854 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
855 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
859 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
861 SessionPtr aMgr = ModelAPI_Session::get();
862 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
864 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
865 XGUI_Workshop* aWorkshop = aConnector->workshop();
866 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
868 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
871 aMenu.addAction(aActivatePartAction);
872 aMenu.exec(aHeader->mapToGlobal(thePnt));
876 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
879 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
881 /// If last line finished on vertex the lines creation sequence has to be break
882 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
883 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
884 // if there is an active widget, find the presented object in it
886 anActiveWidget = aPanel->preselectionWidget();
888 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
890 if (aWidgetValidated)
891 anObject = aWidgetValidated->findPresentedObject(theAIS);
896 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
898 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
899 int aSelected = aObjects.size();
900 SessionPtr aMgr = ModelAPI_Session::get();
901 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
903 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
904 if (aSelected == 1) {
905 bool hasResult = false;
906 bool hasFeature = false;
907 bool hasParameter = false;
908 bool hasSubFeature = false;
909 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
911 ObjectPtr aObject = aObjects.first();
913 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
914 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
915 bool isPart = aPart.get() ||
916 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
918 DocumentPtr aPartDoc;
920 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
922 if (aPart.get()) // this may be null is Part feature is disabled
923 aPartDoc = aPart->partDoc();
925 theMenu->addAction(aActivatePartAction);
926 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
928 } else if (aObject->document() == aMgr->activeDocument()) {
929 if (hasParameter || hasFeature) {
930 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
931 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
932 if (aCurrentOp && aFeature.get()) {
933 if (aCurrentOp->id().toStdString() == aFeature->getKind())
934 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
939 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
941 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
944 bool aNotDeactivate = (aCurrentOp == 0);
945 if (!aNotDeactivate) {
946 aActivatePartAction->setEnabled(false);
950 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
952 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
953 // Do not change activation of parts if an operation active
954 static QStringList aAllowActivationList;
955 if (aAllowActivationList.isEmpty())
956 aAllowActivationList <<
957 QString(PartSetPlugin_Part::ID().c_str()) <<
958 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
959 QString(PartSetPlugin_Remove::ID().c_str());
960 if (myWorkshop->currentOperation() &&
961 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
963 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
964 XGUI_Workshop* aWorkshop = aConnector->workshop();
965 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
966 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
967 QPalette aPalet = aLabel->palette();
969 SessionPtr aMgr = ModelAPI_Session::get();
970 DocumentPtr aActiveDoc = aMgr->activeDocument();
971 if (aActivePartIndex.isValid())
972 aTreeView->setExpanded(aActivePartIndex, false);
973 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
974 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
975 if (aActivePartIndex.isValid())
976 aTreeView->setExpanded(aActivePartIndex, true);
978 aLabel->setPalette(aPalet);
979 aWorkshop->updateCommandStatus();
981 // Update displayed objects in order to update active color
982 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
983 QObjectPtrList aObjects = aDisplayer->displayedObjects();
985 foreach(ObjectPtr aObj, aObjects) {
986 //TODO: replace by redisplay event.
987 aHidden = !aObj->data() || !aObj->data()->isValid() ||
988 aObj->isDisabled() || (!aObj->isDisplayed());
990 aDisplayer->redisplay(aObj, false);
992 aDisplayer->updateViewer();
996 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
998 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1000 SessionPtr aMgr = ModelAPI_Session::get();
1001 if (!theIndex.isValid()) {
1002 aMgr->setActiveDocument(aMgr->moduleDocument());
1005 if (theIndex.column() != 0) // Use only first column
1008 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1009 XGUI_Workshop* aWorkshop = aConnector->workshop();
1010 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1011 // De not use non editable Indexes
1012 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1014 ObjectPtr aObj = aDataModel->object(theIndex);
1016 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1017 if (!aPart.get()) { // Probably this is Feature
1018 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1019 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1020 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1023 if (aPart.get()) { // if this is a part
1024 if (aPart->partDoc() == aMgr->activeDocument()) {
1025 myMenuMgr->activatePartSet();
1033 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1035 // z layer is created for all started operations in order to visualize operation AIS presentation
1037 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1038 if (aContext.IsNull())
1041 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1042 if (myVisualLayerId == 0) {
1043 if (myVisualLayerId == 0)
1044 aViewer->AddZLayer(myVisualLayerId);
1046 TColStd_SequenceOfInteger aZList;
1047 aViewer->GetAllZLayers(aZList);
1048 bool aFound = false;
1049 for (int i = 1; i <= aZList.Length(); i++) {
1050 if (aZList(i) == myVisualLayerId) {
1056 aViewer->AddZLayer(myVisualLayerId);
1058 // if there is an active operation with validated widget,
1059 // the filters of this widget should be activated in the created view
1060 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1062 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1063 if (anActiveWidget) {
1064 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1066 aWSelector->activateSelectionAndFilters(true);
1071 //******************************************************
1072 void PartSet_Module::widgetStateChanged(int thePreviousState)
1074 mySketchMgr->widgetStateChanged(thePreviousState);
1077 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1079 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1082 //******************************************************
1083 void PartSet_Module::beforeOperationStarted(ModuleBase_Operation* theOperation)
1087 //******************************************************
1088 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1090 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1091 mySketchMgr->stopSketch(theOperation);
1095 //******************************************************
1096 void PartSet_Module::onBooleanOperationChange(int theOperation)
1098 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1101 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1102 switch (theOperation) {
1104 aPanel->setWindowTitle(tr("Cut"));
1107 aPanel->setWindowTitle(tr("Fuse"));
1110 aPanel->setWindowTitle(tr("Common"));