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_MenuMgr.h"
18 #include "PartSet_CustomPrs.h"
19 #include "PartSet_IconFactory.h"
21 #include "PartSet_Filters.h"
22 #include "PartSet_FilterInfinite.h"
24 #include <PartSetPlugin_Remove.h>
25 #include <PartSetPlugin_Part.h>
26 #include <PartSetPlugin_Duplicate.h>
28 #include <ModuleBase_Operation.h>
29 #include <ModuleBase_OperationAction.h>
30 #include <ModuleBase_IViewer.h>
31 #include <ModuleBase_IViewWindow.h>
32 #include <ModuleBase_IPropertyPanel.h>
33 #include <ModuleBase_WidgetEditor.h>
34 #include <ModuleBase_WidgetValidated.h>
35 #include <ModuleBase_FilterFactory.h>
36 #include <ModuleBase_Tools.h>
37 #include <ModuleBase_OperationFeature.h>
39 #include <GeomValidators_ShapeType.h>
40 #include <GeomValidators_Finite.h>
41 #include <GeomValidators_Face.h>
42 #include <GeomValidators_ConstructionComposite.h>
43 #include <GeomValidators_ZeroOffset.h>
44 #include <GeomValidators_BooleanArguments.h>
45 #include <GeomValidators_Different.h>
46 #include <GeomValidators_PartitionArguments.h>
49 #include <ModelAPI_Object.h>
50 #include <ModelAPI_Events.h>
51 #include <ModelAPI_Validator.h>
52 #include <ModelAPI_Data.h>
53 #include <ModelAPI_Session.h>
54 #include <GeomValidators_DifferentShapes.h>
55 #include <ModelAPI_ResultBody.h>
56 #include <ModelAPI_AttributeString.h>
58 #include <GeomDataAPI_Point2D.h>
59 #include <GeomDataAPI_Point.h>
60 #include <GeomDataAPI_Dir.h>
62 #include <XGUI_Displayer.h>
63 #include <XGUI_Workshop.h>
64 #include <XGUI_OperationMgr.h>
65 #include <XGUI_PropertyPanel.h>
66 #include <XGUI_ModuleConnector.h>
67 #include <XGUI_ContextMenuMgr.h>
68 #include <XGUI_Tools.h>
69 #include <XGUI_ObjectsBrowser.h>
70 #include <XGUI_SelectionMgr.h>
71 #include <XGUI_DataModel.h>
72 #include <XGUI_ErrorMgr.h>
74 #include <SketchPlugin_Feature.h>
75 #include <SketchPlugin_Sketch.h>
76 #include <SketchPlugin_Line.h>
77 #include <SketchPlugin_Arc.h>
78 #include <SketchPlugin_Circle.h>
79 #include <SketchPlugin_Point.h>
80 #include <SketchPlugin_ConstraintAngle.h>
81 #include <SketchPlugin_ConstraintLength.h>
82 #include <SketchPlugin_ConstraintDistance.h>
83 #include <SketchPlugin_ConstraintParallel.h>
84 #include <SketchPlugin_ConstraintPerpendicular.h>
85 #include <SketchPlugin_ConstraintRadius.h>
87 #include <SketcherPrs_SymbolPrs.h>
88 #include <SketcherPrs_Tools.h>
90 #include <Events_Loop.h>
91 #include <Config_PropManager.h>
92 #include <Config_Keywords.h>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <TopoDS_Vertex.hxx>
97 #include <TopoDS_Shape.hxx>
98 #include <BRep_Tool.hxx>
99 #include <AIS_Dimension.hxx>
102 #include <QMouseEvent>
105 #include <QApplication>
106 #include <QMessageBox>
107 #include <QMainWindow>
110 #include <GeomAlgoAPI_FaceBuilder.h>
111 #include <GeomDataAPI_Dir.h>
113 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
119 /*!Create and return new instance of XGUI_Module*/
120 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
122 return new PartSet_Module(theWshop);
125 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
126 : ModuleBase_IModule(theWshop),
127 myRestartingMode(RM_None), myVisualLayerId(0), myHasConstraintShown(true)
129 new PartSet_IconFactory();
131 mySketchMgr = new PartSet_SketcherMgr(this);
133 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
134 XGUI_Workshop* aWorkshop = aConnector->workshop();
136 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
137 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
138 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
139 this, SLOT(onOperationActivatedByPreselection()));
141 ModuleBase_IViewer* aViewer = theWshop->viewer();
142 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
143 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
144 connect(aViewer, SIGNAL(viewTransformed(int)),
145 SLOT(onViewTransformed(int)));
146 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
147 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
149 myMenuMgr = new PartSet_MenuMgr(this);
150 myCustomPrs = new PartSet_CustomPrs(theWshop);
152 Events_Loop* aLoop = Events_Loop::loop();
153 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
155 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
156 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
159 PartSet_Module::~PartSet_Module()
161 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
162 for (; aIt.More(); aIt.Next()) {
163 Handle(SelectMgr_Filter) aFilter = aIt.Value();
164 if (!aFilter.IsNull())
170 void PartSet_Module::activateSelectionFilters()
172 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
173 for (; aIt.More(); aIt.Next()) {
174 Handle(SelectMgr_Filter) aFilter = aIt.Value();
175 if (!aFilter.IsNull())
176 myWorkshop->viewer()->addSelectionFilter(aFilter);
180 void PartSet_Module::deactivateSelectionFilters()
182 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
183 for (; aIt.More(); aIt.Next()) {
184 Handle(SelectMgr_Filter) aFilter = aIt.Value();
185 if (!aFilter.IsNull())
186 myWorkshop->viewer()->removeSelectionFilter(aFilter);
190 void PartSet_Module::registerValidators()
192 //Registering of validators
193 SessionPtr aMgr = ModelAPI_Session::get();
194 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
195 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
196 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
197 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
198 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
199 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
200 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
201 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
202 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
203 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
204 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
205 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
206 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
207 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
208 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
210 aFactory->registerValidator("GeomValidators_DifferentShapes", new GeomValidators_DifferentShapes);
211 aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
212 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
213 aFactory->registerValidator("GeomValidators_Finite", new GeomValidators_Finite);
215 aFactory->registerValidator("GeomValidators_ConstructionComposite",
216 new GeomValidators_ConstructionComposite);
218 aFactory->registerValidator("GeomValidators_ZeroOffset",
219 new GeomValidators_ZeroOffset);
221 aFactory->registerValidator("GeomValidators_BooleanArguments",
222 new GeomValidators_BooleanArguments);
224 aFactory->registerValidator("PartSet_SketchEntityValidator",
225 new PartSet_SketchEntityValidator);
227 aFactory->registerValidator("GeomValidators_Different",
228 new GeomValidators_Different);
230 aFactory->registerValidator("GeomValidators_PartitionArguments",
231 new GeomValidators_PartitionArguments);
234 void PartSet_Module::registerFilters()
236 //Registering of selection filters
237 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
238 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
241 void PartSet_Module::registerProperties()
243 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
245 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
246 Config_Prop::Integer, SKETCH_WIDTH);
249 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
251 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
254 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
256 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
257 mySketchMgr->commitNestedSketch(theOperation);
260 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
261 if (!aFOperation || aFOperation->isEditOperation())
263 // the selection is cleared after commit the create operation
264 // in order to do not use the same selected objects in the restarted operation
265 // for common behaviour, the selection is cleared even if the operation is not restarted
266 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
267 XGUI_Workshop* aWorkshop = aConnector->workshop();
268 aWorkshop->selector()->clearSelection();
270 /// Restart sketcher operations automatically
271 FeaturePtr aFeature = aFOperation->feature();
272 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
273 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
274 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
275 myRestartingMode == RM_EmptyFeatureUsed)) {
276 myLastOperationId = aFOperation->id();
277 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature() : FeaturePtr();
278 if (!sketchMgr()->sketchSolverError())
279 launchOperation(myLastOperationId);
281 breakOperationSequence();
284 void PartSet_Module::breakOperationSequence()
286 myLastOperationId = "";
287 myLastFeature = FeaturePtr();
288 myRestartingMode = RM_None;
291 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
293 breakOperationSequence();
296 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
298 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
299 mySketchMgr->startSketch(theOperation);
301 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
302 mySketchMgr->startNestedSketch(theOperation);
305 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
307 myCustomPrs->activate(aFOperation->feature(), true);
310 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
312 ModuleBase_IModule::operationResumed(theOperation);
314 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
316 myCustomPrs->activate(aFOperation->feature(), true);
319 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
321 bool isModified = myCustomPrs->deactivate(false);
323 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
324 mySketchMgr->stopSketch(theOperation);
326 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
327 mySketchMgr->stopNestedSketch(theOperation);
330 //VSV: Viewer is updated on feature update and redisplay
332 // XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
333 // XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
334 // aDisplayer->updateViewer();
336 mySketchMgr->onShowConstraintsToggle(myHasConstraintShown);
339 ModuleBase_Operation* PartSet_Module::currentOperation() const
341 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
342 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
343 return anOpMgr->currentOperation();
346 bool PartSet_Module::canUndo() const
348 bool aCanUndo = false;
349 SessionPtr aMgr = ModelAPI_Session::get();
350 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
351 aCanUndo = !aMgr->isOperation();
352 if (!aCanUndo) // check the enable state additionally by sketch manager
353 aCanUndo = aMgr->canUndo();
358 bool PartSet_Module::canRedo() const
360 bool aCanRedo = false;
361 SessionPtr aMgr = ModelAPI_Session::get();
362 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
363 aCanRedo = !aMgr->isOperation();
364 if (!aCanRedo) // check the enable state additionally by sketch manager
365 aCanRedo = aMgr->canRedo();
370 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
373 if (theActionId == "DELETE_CMD" || theActionId == "MOVE_CMD") {
374 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
376 // part features are removed in the PartSet module only.
377 if (aFeature->getKind() == PartSetPlugin_Part::ID())
384 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
386 // the sketch manager put the restriction to the objects erase
387 return mySketchMgr->canEraseObject(theObject);
390 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
392 // the sketch manager put the restriction to the objects display
393 return mySketchMgr->canDisplayObject(theObject);
396 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
398 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
400 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
401 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
402 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
403 if (isSketchOp || isNestedOp) {
404 // in active sketch operation it is possible to activate operation object in selection
405 // in the edit operation, e.g. points of the line can be moved when the line is edited
406 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
407 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
412 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
414 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
417 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
419 myMenuMgr->updateViewerMenu(theStdActions);
422 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
424 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
425 if (anError.isEmpty())
426 anError = sketchMgr()->getFeatureError(theFeature);
431 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
432 QStringList& theIds) const
434 myMenuMgr->grantedOperationIds(theOperation, theIds);
436 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
437 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
438 XGUI_Workshop* aWorkshop = aConnector->workshop();
440 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
444 void PartSet_Module::activeSelectionModes(QIntList& theModes)
447 if (mySketchMgr->activeSketch().get())
448 PartSet_SketcherMgr::sketchSelectionModes(theModes);
451 bool PartSet_Module::isMouseOverWindow()
453 return mySketchMgr->isMouseOverWindow();
456 void PartSet_Module::closeDocument()
461 void PartSet_Module::clearViewer()
463 myCustomPrs->clearPrs();
465 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
466 XGUI_Workshop* aWorkshop = aConnector->workshop();
467 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
468 aDisplayer->deactivateSelectionFilters();
471 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
473 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
477 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
478 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation())) {
479 // we have to manually activate the sketch label in edit mode
480 aPanel->activateWidget(aPanel->modelWidgets().first());
484 // Restart last operation type
485 if ((aFOperation->id() == myLastOperationId) && myLastFeature) {
486 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
487 if (aFOperation->id().toStdString() == SketchPlugin_Line::ID()) {
488 // Initialise new line with first point equal to end of previous
489 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
491 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
492 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
493 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
495 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
496 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), aFOperation->feature(),
497 aWgt->attributeID(), aPoint->x(), aPoint->y());
498 aPanel->activateNextWidget(aPnt2dWgt);
506 void PartSet_Module::onSelectionChanged()
508 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
512 bool isSketcherOp = false;
513 // An edit operation is enable only if the current opeation is the sketch operation
514 if (mySketchMgr->activeSketch()) {
515 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
516 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
519 // Editing of constraints can be done on selection
520 ModuleBase_ISelection* aSelect = myWorkshop->selection();
521 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
522 if (aSelected.size() == 1) {
523 ModuleBase_ViewerPrs aPrs = aSelected.first();
524 ObjectPtr aObject = aPrs.object();
525 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
527 std::string aId = aFeature->getKind();
528 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
529 (aId == SketchPlugin_ConstraintLength::ID()) ||
530 (aId == SketchPlugin_ConstraintDistance::ID()) ||
531 (aId == SketchPlugin_ConstraintAngle::ID())) {
532 editFeature(aFeature);
539 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
541 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
542 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
543 anOpMgr->onKeyReleased(theEvent);
546 void PartSet_Module::onEnterReleased()
548 myRestartingMode = RM_EmptyFeatureUsed;
551 void PartSet_Module::onOperationActivatedByPreselection()
553 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
554 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
555 // Set final definitions if they are necessary
556 //propertyPanelDefined(aOperation);
558 /// Commit sketcher operations automatically
559 anOperation->commit();
563 void PartSet_Module::onNoMoreWidgets()
565 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
567 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
568 if (myRestartingMode != RM_Forbided)
569 myRestartingMode = RM_LastFeatureUsed;
570 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
571 XGUI_Workshop* aWorkshop = aConnector->workshop();
572 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
573 // do nothing if the feature can not be applyed
574 if (anOpMgr->isApplyEnabled())
575 anOperation->commit();
580 void PartSet_Module::onVertexSelected()
582 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
583 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
584 /// If last line finished on vertex the lines creation sequence has to be break
585 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
586 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
587 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
588 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
589 bool aFoundWidget = false;
590 bool aFoundObligatory = false;
591 for (; anIt != aLast && !aFoundObligatory; anIt++) {
593 aFoundWidget = *anIt == anActiveWidget;
595 aFoundObligatory = (*anIt)->isObligatory();
597 if (!aFoundObligatory)
598 myRestartingMode = RM_Forbided;
602 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
603 Config_WidgetAPI* theWidgetApi, std::string theParentId)
605 ModuleBase_IWorkshop* aWorkshop = workshop();
606 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
607 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
608 ModuleBase_ModelWidget* aWgt = NULL;
609 if (theType == "sketch-start-label") {
610 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
611 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
612 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
613 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
614 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
615 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
617 } else if (theType == "sketch-2dpoint_selector") {
618 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
619 theWidgetApi, theParentId);
620 aPointWgt->setSketch(mySketchMgr->activeSketch());
621 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
623 } else if (theType == "sketch-2dpoint_flyout_selector") {
624 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
625 theWidgetApi, theParentId);
626 aPointWgt->setSketch(mySketchMgr->activeSketch());
627 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
629 } else if (theType == "point2ddistance") {
630 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
631 aWorkshop, theWidgetApi, theParentId);
632 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
634 } else if(theType == "point2dangle") {
635 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
636 aWorkshop, theWidgetApi, theParentId);
637 anAngleWgt->setSketch(mySketchMgr->activeSketch());
639 } else if (theType == "sketch_shape_selector") {
640 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
641 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
642 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
643 aWgt = aShapeSelectorWgt;
644 } else if (theType == "sketch_multi_selector") {
645 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
646 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
647 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
648 aWgt = aShapeSelectorWgt;
649 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
650 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
651 } else if (theType == "export_file_selector") {
652 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
653 } else if (theType == "sketch_launcher") {
654 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
660 bool PartSet_Module::deleteObjects()
662 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
663 XGUI_Workshop* aWorkshop = aConnector->workshop();
664 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
666 //SessionPtr aMgr = ModelAPI_Session::get();
667 // 1. check whether the delete should be processed in the module
668 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
669 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
670 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
671 if (isSketchOp || isNestedOp) {
672 // 2. find selected presentations
673 // selected objects should be collected before the current operation abort because
674 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
675 ModuleBase_ISelection* aSel = workshop()->selection();
676 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
677 // if there are no selected objects in the viewer, that means that the selection in another
678 // place cased this method. It is necessary to return the false value to understande in above
679 // method that delete is not processed
680 if (aSelectedObj.count() == 0)
683 // avoid delete of the objects, which are not belong to the current sketch
684 // in order to do not delete results of other sketches
685 QObjectPtrList aSketchObjects;
686 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
687 for ( ; anIt != aLast; anIt++) {
688 ObjectPtr anObject = *anIt;
689 if (mySketchMgr->isObjectOfSketch(anObject)) {
690 // sketch feature should be used in this list because workshop deletes features only
691 // results are skipped
692 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
693 aSketchObjects.append(aSketchFeature);
696 // if the selection contains only local selected presentations from other sketches,
697 // the Delete operation should not be done at all
698 if (aSketchObjects.size() == 0)
701 // 3. start operation
702 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
703 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
705 // the active nested sketch operation should be aborted unconditionally
706 // the Delete action should be additionally granted for the Sketch operation
707 // in order to do not abort/commit it
708 if (!anOpMgr->canStartOperation(anOpAction->id()))
709 return true; // the objects are processed but can not be deleted
711 anOpMgr->startOperation(anOpAction);
713 // 4. delete features
714 // sketch feature should be skipped, only sub-features can be removed
715 // when sketch operation is active
716 aWorkshop->deleteFeatures(aSketchObjects);
718 anOpMgr->commitOperation();
721 bool isPartRemoved = false;
722 // Delete part with help of PartSet plugin
723 // TODO: the deleted objects has to be processed by multiselection
724 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
725 if (aObjects.size() == 1) {
726 ObjectPtr aObj = aObjects.first();
727 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
728 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
729 // Remove feature should be created in the document of the part results
730 ResultPtr aPartResult = aFeature->firstResult();
731 if (aPartResult.get()) {
732 std::shared_ptr<ModelAPI_ResultPart> aPart =
733 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
734 DocumentPtr aPartDoc = aPart->partDoc();
735 if (aPartDoc.get()) {
736 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
737 (PartSetPlugin_Remove::ID().c_str(), this);
738 if (!anOpMgr->canStartOperation(anOpAction->id()))
739 return true; // the objects are processed but can not be deleted
741 anOpMgr->startOperation(anOpAction);
743 FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
746 anOpMgr->commitOperation();
747 isPartRemoved = true;
752 return isPartRemoved;
757 void PartSet_Module::onFeatureTriggered()
759 QAction* aCmd = dynamic_cast<QAction*>(sender());
760 if (aCmd->isCheckable() && aCmd->isChecked()) {
761 // 1. check whether the delete should be processed in the module
762 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
763 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
765 // in case if in the viewer nothing is displayed, the create operation should not be
766 // comitted even if all values of the feature are initialized
767 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
768 // the action information should be saved before the operation is aborted
769 // because this abort leads to update command status, which unchecks this action
770 anOperation->abort();
771 launchOperation(aCmd->data().toString());
775 ModuleBase_IModule::onFeatureTriggered();
778 void PartSet_Module::launchOperation(const QString& theCmdId)
780 if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
781 // Show constraints if a constraint was anOperation
782 myHasConstraintShown = mySketchMgr->isConstraintsShown();
783 mySketchMgr->onShowConstraintsToggle(true);
785 ModuleBase_IModule::launchOperation(theCmdId);
789 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
791 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
792 if (!anAIS.IsNull()) {
793 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
794 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
795 if (!aDim.IsNull()) {
796 aCtx->SetZLayer(aDim, myVisualLayerId);
798 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
800 aCtx->SetZLayer(aCons, myVisualLayerId);
805 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
808 // it should be recomputed in order to disappear in the viewer if the corresponded object
810 //if (myCustomPrs->isActive())
811 // myCustomPrs->redisplay(theObject, false);
814 void PartSet_Module::onViewTransformed(int theTrsfType)
816 // Set length of arrows constant in pixel size
817 // if the operation is panning or rotate or panglobal then do nothing
818 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
820 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
821 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
822 if (aContext.IsNull())
825 //Handle(V3d_View) aView = aViewer->activeView();
827 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
828 XGUI_Workshop* aWorkshop = aConnector->workshop();
829 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
830 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
831 Handle(V3d_View) aView;
833 for (aV3dViewer->InitDefinedViews();
834 aV3dViewer->MoreDefinedViews();
835 aV3dViewer->NextDefinedViews()) {
836 Handle(V3d_View) aV = aV3dViewer->DefinedView();
837 double aS = aV->Scale();
845 double aLen = aView->Convert(20);
847 double aPrevLen = SketcherPrs_Tools::getArrowSize();
848 SketcherPrs_Tools::setArrowSize(aLen);
849 const double aPrevScale = aViewer->Scale(aViewer->activeView());
850 const double aCurScale = aViewer->activeView()->Camera()->Scale();
851 aViewer->SetScale(aViewer->activeView(), aCurScale);
852 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
853 bool isModified = false;
854 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
855 foreach (AISObjectPtr aAIS, aPrsList) {
856 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
858 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
859 if (!aDim.IsNull()) {
860 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
861 aContext->Redisplay(aDim, false);
866 aDisplayer->updateViewer();
869 bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
871 bool isRedisplayed = false;
872 if (myCustomPrs->isActive())
873 isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
875 return isRedisplayed;
878 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
880 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
882 QLineEdit* aLabel = aOB->activeDocLabel();
883 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
884 SLOT(onActiveDocPopup(const QPoint&)));
885 //QPalette aPalet = aLabel->palette();
886 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
887 //aLabel->setPalette(aPalet);
888 aOB->treeView()->setExpandsOnDoubleClick(false);
889 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
890 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
894 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
896 SessionPtr aMgr = ModelAPI_Session::get();
897 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
899 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
900 XGUI_Workshop* aWorkshop = aConnector->workshop();
901 QLineEdit* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
903 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
906 aMenu.addAction(aActivatePartAction);
907 aMenu.exec(aHeader->mapToGlobal(thePnt));
911 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
914 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
916 /// If last line finished on vertex the lines creation sequence has to be break
917 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
918 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
919 // if there is an active widget, find the presented object in it
921 anActiveWidget = aPanel->preselectionWidget();
923 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
925 if (aWidgetValidated)
926 anObject = aWidgetValidated->findPresentedObject(theAIS);
931 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
933 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
934 int aSelected = aObjects.size();
935 SessionPtr aMgr = ModelAPI_Session::get();
936 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
938 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
939 if (aSelected == 1) {
940 bool hasResult = false;
941 bool hasFeature = false;
942 bool hasParameter = false;
943 bool hasSubFeature = false;
944 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
946 ObjectPtr aObject = aObjects.first();
948 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
949 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
950 bool isPart = aPart.get() ||
951 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
953 DocumentPtr aPartDoc;
955 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
957 if (aPart.get()) // this may be null is Part feature is disabled
958 aPartDoc = aPart->partDoc();
960 theMenu->addAction(aActivatePartAction);
961 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
963 } else if (aObject->document() == aMgr->activeDocument()) {
964 if (hasParameter || hasFeature) {
965 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
966 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
967 if (aCurrentOp && aFeature.get()) {
968 if (aCurrentOp->id().toStdString() == aFeature->getKind())
969 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
974 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
976 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
979 bool aNotDeactivate = (aCurrentOp == 0);
980 if (!aNotDeactivate) {
981 aActivatePartAction->setEnabled(false);
985 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
987 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
988 // Do not change activation of parts if an operation active
989 static QStringList aAllowActivationList;
990 if (aAllowActivationList.isEmpty())
991 aAllowActivationList <<
992 QString(PartSetPlugin_Part::ID().c_str()) <<
993 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
994 QString(PartSetPlugin_Remove::ID().c_str());
995 if (myWorkshop->currentOperation() &&
996 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
998 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
999 XGUI_Workshop* aWorkshop = aConnector->workshop();
1000 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1001 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1002 QPalette aPalet = aLabel->palette();
1004 SessionPtr aMgr = ModelAPI_Session::get();
1005 DocumentPtr aActiveDoc = aMgr->activeDocument();
1006 if (aActivePartIndex.isValid())
1007 aTreeView->setExpanded(aActivePartIndex, false);
1008 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1009 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1010 if (aActivePartIndex.isValid())
1011 aTreeView->setExpanded(aActivePartIndex, true);
1013 aLabel->setPalette(aPalet);
1014 aWorkshop->updateCommandStatus();
1016 // Update displayed objects in order to update active color
1017 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1018 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1020 foreach(ObjectPtr aObj, aObjects) {
1021 //TODO: replace by redisplay event.
1022 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1023 aObj->isDisabled() || (!aObj->isDisplayed());
1025 aDisplayer->redisplay(aObj, false);
1027 aDisplayer->updateViewer();
1031 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1033 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1035 SessionPtr aMgr = ModelAPI_Session::get();
1036 if (!theIndex.isValid()) {
1037 aMgr->setActiveDocument(aMgr->moduleDocument());
1040 if (theIndex.column() != 0) // Use only first column
1043 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1044 XGUI_Workshop* aWorkshop = aConnector->workshop();
1045 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1046 // De not use non editable Indexes
1047 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1049 ObjectPtr aObj = aDataModel->object(theIndex);
1051 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1052 if (!aPart.get()) { // Probably this is Feature
1053 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1054 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1055 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1058 if (aPart.get()) { // if this is a part
1059 if (aPart->partDoc() == aMgr->activeDocument()) {
1060 myMenuMgr->activatePartSet();
1068 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1070 // z layer is created for all started operations in order to visualize operation AIS presentation
1072 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1073 if (aContext.IsNull())
1076 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1077 if (myVisualLayerId == 0) {
1078 if (myVisualLayerId == 0)
1079 aViewer->AddZLayer(myVisualLayerId);
1081 TColStd_SequenceOfInteger aZList;
1082 aViewer->GetAllZLayers(aZList);
1083 bool aFound = false;
1084 for (int i = 1; i <= aZList.Length(); i++) {
1085 if (aZList(i) == myVisualLayerId) {
1091 aViewer->AddZLayer(myVisualLayerId);
1093 // if there is an active operation with validated widget,
1094 // the filters of this widget should be activated in the created view
1095 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1097 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1098 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1099 if (anActiveWidget) {
1100 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1102 if (aWidgetValidated)
1103 aWidgetValidated->activateFilters(true);