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 "ModuleBase_WidgetValidated.h"
8 #include "PartSet_WidgetPoint2d.h"
9 #include "PartSet_WidgetPoint2dDistance.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>
20 #include "PartSet_Filters.h"
21 #include "PartSet_FilterInfinite.h"
23 #include <PartSetPlugin_Remove.h>
24 #include <PartSetPlugin_Part.h>
25 #include <PartSetPlugin_Duplicate.h>
27 #include <ModuleBase_Operation.h>
28 #include <ModuleBase_IViewer.h>
29 #include <ModuleBase_IViewWindow.h>
30 #include <ModuleBase_IPropertyPanel.h>
31 #include <ModuleBase_WidgetEditor.h>
32 #include <ModuleBase_FilterFactory.h>
33 #include <ModuleBase_Tools.h>
34 #include <GeomValidators_ShapeType.h>
36 #include <GeomValidators_Face.h>
37 #include <GeomValidators_ConstructionComposite.h>
38 #include <GeomValidators_ZeroOffset.h>
39 #include <GeomValidators_BooleanArguments.h>
40 #include <GeomValidators_Different.h>
43 #include <ModelAPI_Object.h>
44 #include <ModelAPI_Events.h>
45 #include <ModelAPI_Validator.h>
46 #include <ModelAPI_Data.h>
47 #include <ModelAPI_Session.h>
48 #include <ModelAPI_ShapeValidator.h>
50 #include <GeomDataAPI_Point2D.h>
51 #include <GeomDataAPI_Point.h>
52 #include <GeomDataAPI_Dir.h>
54 #include <XGUI_Displayer.h>
55 #include <XGUI_Workshop.h>
56 #include <XGUI_OperationMgr.h>
57 #include <XGUI_PropertyPanel.h>
58 #include <XGUI_ModuleConnector.h>
59 #include <XGUI_ContextMenuMgr.h>
60 #include <XGUI_Tools.h>
61 #include <XGUI_ObjectsBrowser.h>
62 #include <XGUI_SelectionMgr.h>
64 #include <SketchPlugin_Feature.h>
65 #include <SketchPlugin_Sketch.h>
66 #include <SketchPlugin_Line.h>
67 #include <SketchPlugin_Arc.h>
68 #include <SketchPlugin_Circle.h>
69 #include <SketchPlugin_Point.h>
70 #include <SketchPlugin_ConstraintLength.h>
71 #include <SketchPlugin_ConstraintDistance.h>
72 #include <SketchPlugin_ConstraintParallel.h>
73 #include <SketchPlugin_ConstraintPerpendicular.h>
74 #include <SketchPlugin_ConstraintRadius.h>
76 #include <SketcherPrs_SymbolPrs.h>
77 #include <SketcherPrs_Tools.h>
79 #include <Events_Loop.h>
80 #include <Config_PropManager.h>
81 #include <Config_Keywords.h>
83 #include <StdSelect_TypeOfFace.hxx>
84 #include <TopoDS_Vertex.hxx>
86 #include <TopoDS_Shape.hxx>
87 #include <BRep_Tool.hxx>
88 #include <AIS_Dimension.hxx>
91 #include <QMouseEvent>
94 #include <QApplication>
95 #include <QMessageBox>
96 #include <QMainWindow>
99 #include <GeomAlgoAPI_FaceBuilder.h>
100 #include <GeomDataAPI_Dir.h>
102 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
110 /*!Create and return new instance of XGUI_Module*/
111 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
113 return new PartSet_Module(theWshop);
116 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
117 : ModuleBase_IModule(theWshop),
118 myRestartingMode(RM_None), myVisualLayerId(0)
120 mySketchMgr = new PartSet_SketcherMgr(this);
121 myDataModel = new PartSet_DocumentDataModel(this);
123 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
124 XGUI_Workshop* aWorkshop = aConnector->workshop();
126 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
127 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
128 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
129 this, SLOT(onOperationActivatedByPreselection()));
131 ModuleBase_IViewer* aViewer = theWshop->viewer();
132 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
133 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
134 connect(aViewer, SIGNAL(viewTransformed(int)),
135 SLOT(onViewTransformed(int)));
136 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
137 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
139 myMenuMgr = new PartSet_MenuMgr(this);
140 myCustomPrs = new PartSet_CustomPrs(theWshop);
142 Events_Loop* aLoop = Events_Loop::loop();
143 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
145 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
146 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
149 PartSet_Module::~PartSet_Module()
151 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
152 for (; aIt.More(); aIt.Next()) {
153 Handle(SelectMgr_Filter) aFilter = aIt.Value();
154 if (!aFilter.IsNull())
160 void PartSet_Module::activateSelectionFilters()
162 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
163 for (; aIt.More(); aIt.Next()) {
164 Handle(SelectMgr_Filter) aFilter = aIt.Value();
165 if (!aFilter.IsNull())
166 myWorkshop->viewer()->addSelectionFilter(aFilter);
170 void PartSet_Module::deactivateSelectionFilters()
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()->removeSelectionFilter(aFilter);
180 void PartSet_Module::registerValidators()
182 //Registering of validators
183 SessionPtr aMgr = ModelAPI_Session::get();
184 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
185 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
186 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
187 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
188 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
189 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
190 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
191 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
192 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
193 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
194 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
196 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
197 aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
199 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
201 aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
202 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
204 aFactory->registerValidator("GeomValidators_ConstructionComposite",
205 new GeomValidators_ConstructionComposite);
207 aFactory->registerValidator("GeomValidators_ZeroOffset",
208 new GeomValidators_ZeroOffset);
210 aFactory->registerValidator("GeomValidators_BooleanArguments",
211 new GeomValidators_BooleanArguments);
213 aFactory->registerValidator("PartSet_SketchEntityValidator",
214 new PartSet_SketchEntityValidator);
216 aFactory->registerValidator("PartSet_SameTypeAttr",
217 new PartSet_SameTypeAttrValidator);
219 aFactory->registerValidator("GeomValidators_Different",
220 new GeomValidators_Different);
223 void PartSet_Module::registerFilters()
225 //Registering of selection filters
226 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
227 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
230 void PartSet_Module::registerProperties()
232 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
234 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
235 Config_Prop::Integer, SKETCH_WIDTH);
238 void PartSet_Module::onOperationCommitted(ModuleBase_Operation* theOperation)
240 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
241 mySketchMgr->commitNestedSketch(theOperation);
244 if (theOperation->isEditOperation())
246 // the selection is cleared after commit the create operation
247 // in order to do not use the same selected objects in the restarted operation
248 // for common behaviour, the selection is cleared even if the operation is not restarted
249 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
250 XGUI_Workshop* aWorkshop = aConnector->workshop();
251 aWorkshop->selector()->clearSelection();
253 /// Restart sketcher operations automatically
254 FeaturePtr aFeature = theOperation->feature();
255 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
256 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
257 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
258 myRestartingMode == RM_EmptyFeatureUsed)) {
259 myLastOperationId = theOperation->id();
260 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
262 launchOperation(myLastOperationId);
264 breakOperationSequence();
267 void PartSet_Module::breakOperationSequence()
269 myLastOperationId = "";
270 myLastFeature = FeaturePtr();
271 myRestartingMode = RM_None;
274 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
276 breakOperationSequence();
279 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
281 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
282 mySketchMgr->startSketch(theOperation);
284 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
285 mySketchMgr->startNestedSketch(theOperation);
288 myCustomPrs->activate(theOperation->feature());
291 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
293 myCustomPrs->deactivate();
295 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
296 mySketchMgr->stopSketch(theOperation);
298 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
299 mySketchMgr->stopNestedSketch(theOperation);
303 ModuleBase_Operation* PartSet_Module::currentOperation() const
305 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
306 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
307 return anOpMgr->currentOperation();
310 bool PartSet_Module::canUndo() const
312 bool aCanUndo = false;
313 SessionPtr aMgr = ModelAPI_Session::get();
314 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
315 aCanUndo = !aMgr->isOperation();
316 if (!aCanUndo) // check the enable state additionally by sketch manager
317 aCanUndo = aMgr->canUndo();
322 bool PartSet_Module::canRedo() const
324 bool aCanRedo = false;
325 SessionPtr aMgr = ModelAPI_Session::get();
326 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
327 aCanRedo = !aMgr->isOperation();
328 if (!aCanRedo) // check the enable state additionally by sketch manager
329 aCanRedo = aMgr->canRedo();
334 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
337 if (theActionId == "DELETE_CMD" || theActionId == "MOVE_CMD") {
338 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
340 // part features are removed in the PartSet module only.
341 if (aFeature->getKind() == PartSetPlugin_Part::ID())
348 bool PartSet_Module::canCommitOperation() const
350 return mySketchMgr->canCommitOperation();
353 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
355 // the sketch manager put the restriction to the objects display
356 return mySketchMgr->canDisplayObject(theObject);
359 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
361 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
363 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
364 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
365 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
366 if (isSketchOp || isNestedOp) {
367 // in active sketch operation it is possible to activate operation object in selection
368 // in the edit operation, e.g. points of the line can be moved when the line is edited
369 aCanActivate = aCanActivate || anOperation->isEditOperation();
374 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
376 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
379 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
381 myMenuMgr->updateViewerMenu(theStdActions);
385 void PartSet_Module::activeSelectionModes(QIntList& theModes)
388 if (mySketchMgr->activeSketch().get())
389 PartSet_SketcherMgr::sketchSelectionModes(theModes);
392 bool PartSet_Module::isMouseOverWindow()
394 return mySketchMgr->isMouseOverWindow();
397 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
399 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
400 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
401 // we have to manually activate the sketch label in edit mode
402 aPanel->activateWidget(aPanel->modelWidgets().first());
406 // Restart last operation type
407 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
408 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
409 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
410 // Initialise new line with first point equal to end of previous
411 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
413 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
414 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
415 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
417 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
418 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
419 aWgt->attributeID(), aPoint->x(), aPoint->y());
420 aPanel->activateNextWidget(aPnt2dWgt);
428 void PartSet_Module::onSelectionChanged()
430 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
434 bool isSketcherOp = false;
435 // An edit operation is enable only if the current opeation is the sketch operation
436 if (mySketchMgr->activeSketch()) {
437 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
438 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
441 // Editing of constraints can be done on selection
442 ModuleBase_ISelection* aSelect = myWorkshop->selection();
443 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
444 if (aSelected.size() == 1) {
445 ModuleBase_ViewerPrs aPrs = aSelected.first();
446 ObjectPtr aObject = aPrs.object();
447 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
449 std::string aId = aFeature->getKind();
450 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
451 (aId == SketchPlugin_ConstraintLength::ID()) ||
452 (aId == SketchPlugin_ConstraintDistance::ID())) {
453 editFeature(aFeature);
460 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
462 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
463 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
464 anOpMgr->onKeyReleased(theEvent);
467 void PartSet_Module::onEnterReleased()
469 myRestartingMode = RM_EmptyFeatureUsed;
472 void PartSet_Module::onOperationActivatedByPreselection()
474 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
475 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
476 // Set final definitions if they are necessary
477 //propertyPanelDefined(aOperation);
479 /// Commit sketcher operations automatically
480 anOperation->commit();
484 void PartSet_Module::onNoMoreWidgets()
486 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
488 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
489 if (myRestartingMode != RM_Forbided)
490 myRestartingMode = RM_LastFeatureUsed;
491 anOperation->commit();
496 void PartSet_Module::onVertexSelected()
498 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
499 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
500 /// If last line finished on vertex the lines creation sequence has to be break
501 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
502 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
503 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
504 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
505 bool aFoundWidget = false;
506 bool aFoundObligatory = false;
507 for (; anIt != aLast && !aFoundObligatory; anIt++) {
509 aFoundWidget = *anIt == anActiveWidget;
511 aFoundObligatory = (*anIt)->isObligatory();
513 if (!aFoundObligatory)
514 myRestartingMode = RM_Forbided;
518 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
519 Config_WidgetAPI* theWidgetApi, std::string theParentId)
521 ModuleBase_IWorkshop* aWorkshop = workshop();
522 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
523 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
524 ModuleBase_ModelWidget* aWgt = NULL;
525 if (theType == "sketch-start-label") {
526 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
527 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
528 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
529 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
530 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
531 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
533 } else if (theType == "sketch-2dpoint_selector") {
534 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
535 theWidgetApi, theParentId);
536 aPointWgt->setSketch(mySketchMgr->activeSketch());
537 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
539 } else if (theType == "point2ddistance") {
540 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
541 aWorkshop, theWidgetApi, theParentId);
542 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
544 } else if(theType == "point2dangle") {
545 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
546 aWorkshop, theWidgetApi, theParentId);
547 anAngleWgt->setSketch(mySketchMgr->activeSketch());
549 } else if (theType == "sketch_shape_selector") {
550 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
551 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
552 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
553 aWgt = aShapeSelectorWgt;
554 } else if (theType == "sketch_multi_selector") {
555 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
556 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
557 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
558 aWgt = aShapeSelectorWgt;
559 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
560 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
561 } else if (theType == "export_file_selector") {
562 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
563 } else if (theType == "sketch_launcher") {
564 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
570 bool PartSet_Module::deleteObjects()
572 SessionPtr aMgr = ModelAPI_Session::get();
573 // 1. check whether the delete should be processed in the module
574 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
575 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
576 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
577 if (isSketchOp || isNestedOp) {
578 // 2. find selected presentations
579 // selected objects should be collected before the current operation abort because
580 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
581 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
582 XGUI_Workshop* aWorkshop = aConnector->workshop();
583 ModuleBase_ISelection* aSel = workshop()->selection();
584 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
585 // if there are no selected objects in the viewer, that means that the selection in another
586 // place cased this method. It is necessary to return the false value to understande in above
587 // method that delete is not processed
588 if (aSelectedObj.count() == 0)
591 // avoid delete of the objects, which are not belong to the current sketch
592 // in order to do not delete results of other sketches
593 QObjectPtrList aSketchObjects;
594 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
595 for ( ; anIt != aLast; anIt++) {
596 ObjectPtr anObject = *anIt;
597 if (mySketchMgr->isObjectOfSketch(anObject)) {
598 // sketch feature should be used in this list because workshop deletes features only
599 // results are skipped
600 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
601 aSketchObjects.append(aSketchFeature);
604 // if the selection contains only local selected presentations from other sketches,
605 // the Delete operation should not be done at all
606 if (aSketchObjects.size() == 0)
609 // the active nested sketch operation should be aborted unconditionally
611 anOperation->abort();
613 // 3. start operation
614 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
615 aMgr->startOperation(aDescription.toStdString());
617 // 4. delete features
618 // sketch feature should be skipped, only sub-features can be removed
619 // when sketch operation is active
620 aWorkshop->deleteFeatures(aSketchObjects);
622 aWorkshop->displayer()->updateViewer();
623 aMgr->finishOperation();
625 bool isPartRemoved = false;
626 // Delete part with help of PartSet plugin
627 // TODO: the deleted objects has to be processed by multiselection
628 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
629 if (aObjects.size() == 1) {
630 ObjectPtr aObj = aObjects.first();
631 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
632 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
633 // Remove feature should be created in the document of the part results
634 ResultPtr aPartResult = aFeature->firstResult();
635 if (aPartResult.get()) {
636 std::shared_ptr<ModelAPI_ResultPart> aPart =
637 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
638 DocumentPtr aPartDoc = aPart->partDoc();
639 if (aPartDoc.get()) {
640 aMgr->startOperation(PartSetPlugin_Remove::ID());
641 FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
643 aMgr->finishOperation();
644 isPartRemoved = true;
649 return isPartRemoved;
654 void PartSet_Module::onFeatureTriggered()
656 SessionPtr aMgr = ModelAPI_Session::get();
657 // 1. check whether the delete should be processed in the module
658 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
659 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
661 // in case if in the viewer nothing is displayed, the create operation should not be
662 // comitted even if all values of the feature are initialized
663 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
664 QAction* aCmd = dynamic_cast<QAction*>(sender());
665 //Do nothing on uncheck
666 if (aCmd->isCheckable() && !aCmd->isChecked())
669 // the action information should be saved before the operation is aborted
670 // because this abort leads to update command status, which unchecks this action
671 anOperation->abort();
673 launchOperation(aCmd->data().toString());
676 ModuleBase_IModule::onFeatureTriggered();
679 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
681 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
682 if (!anAIS.IsNull()) {
683 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
684 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
685 if (!aDim.IsNull()) {
686 aCtx->SetZLayer(aDim, myVisualLayerId);
688 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
690 aCtx->SetZLayer(aCons, myVisualLayerId);
695 void PartSet_Module::onViewTransformed(int theTrsfType)
697 // Set length of arrows constant in pixel size
698 // if the operation is panning or rotate or panglobal then do nothing
699 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
702 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
703 //Handle(V3d_View) aView = aViewer->activeView();
705 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
706 XGUI_Workshop* aWorkshop = aConnector->workshop();
707 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
708 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
710 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
711 Handle(V3d_View) aView;
713 for (aV3dViewer->InitDefinedViews();
714 aV3dViewer->MoreDefinedViews();
715 aV3dViewer->NextDefinedViews()) {
716 Handle(V3d_View) aV = aV3dViewer->DefinedView();
717 double aS = aV->Scale();
725 double aLen = aView->Convert(20);
727 double aPrevLen = SketcherPrs_Tools::getArrowSize();
728 SketcherPrs_Tools::setArrowSize(aLen);
729 const double aPrevScale = aViewer->Scale(aViewer->activeView());
730 const double aCurScale = aViewer->activeView()->Camera()->Scale();
731 aViewer->SetScale(aViewer->activeView(), aCurScale);
732 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
733 bool isModified = false;
734 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
735 foreach (AISObjectPtr aAIS, aPrsList) {
736 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
738 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
739 if (!aDim.IsNull()) {
740 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
741 aContext->Redisplay(aDim, false);
746 aDisplayer->updateViewer();
749 void PartSet_Module::customizeObject(ObjectPtr theObject)
751 if (myCustomPrs->isActive())
752 myCustomPrs->customize(theObject);
755 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
757 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
759 QLineEdit* aLabel = aOB->activeDocLabel();
760 QPalette aPalet = aLabel->palette();
761 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
762 aLabel->setPalette(aPalet);
763 aOB->treeView()->setExpandsOnDoubleClick(false);
764 #ifdef ModuleDataModel
765 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
766 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
767 connect(aOB, SIGNAL(headerMouseDblClicked(const QModelIndex&)),
768 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
769 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
770 myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&)));
775 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
778 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
780 /// If last line finished on vertex the lines creation sequence has to be break
781 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
782 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
783 // if there is an active widget, find the presented object in it
785 anActiveWidget = aPanel->preselectionWidget();
787 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
789 if (aWidgetValidated)
790 anObject = aWidgetValidated->findPresentedObject(theAIS);
795 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
797 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
798 int aSelected = aObjects.size();
799 SessionPtr aMgr = ModelAPI_Session::get();
800 if (aSelected == 1) {
801 bool hasResult = false;
802 bool hasFeature = false;
803 bool hasParameter = false;
804 bool hasSubFeature = false;
805 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
807 ObjectPtr aObject = aObjects.first();
809 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
810 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
811 bool isPart = aPart.get() ||
812 (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
814 DocumentPtr aPartDoc;
816 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
818 if (aPart.get()) // this may be null is Part feature is disabled
819 aPartDoc = aPart->partDoc();
820 if (aMgr->activeDocument() == aPartDoc)
821 theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
823 theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
824 } else if (aObject->document() == aMgr->activeDocument()) {
825 if (hasParameter || hasFeature)
826 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
828 } else { // If feature is 0 the it means that selected root object (document)
829 if (aMgr->activeDocument() != aMgr->moduleDocument())
830 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
832 } else if (aSelected == 0) {
833 // if there is no selection then it means that upper label is selected
834 QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
835 if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
836 if (aMgr->activeDocument() != aMgr->moduleDocument())
837 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
839 bool aCanDeactivate = (myWorkshop->currentOperation() == 0);
840 myMenuMgr->action("ACTIVATE_PARTSET_CMD")->setEnabled(aCanDeactivate);
841 myMenuMgr->action("DEACTIVATE_PART_CMD")->setEnabled(aCanDeactivate);
842 myMenuMgr->action("ACTIVATE_PART_CMD")->setEnabled(aCanDeactivate);
845 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
847 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
848 // Do not change activation of parts if an operation active
849 static QStringList aAllowActivationList;
850 if (aAllowActivationList.isEmpty())
851 aAllowActivationList <<
852 QString(PartSetPlugin_Part::ID().c_str()) <<
853 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
854 QString(PartSetPlugin_Remove::ID().c_str());
855 if (myWorkshop->currentOperation() &&
856 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
858 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
859 XGUI_Workshop* aWorkshop = aConnector->workshop();
860 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
861 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
862 QPalette aPalet = aLabel->palette();
864 SessionPtr aMgr = ModelAPI_Session::get();
865 DocumentPtr aActiveDoc = aMgr->activeDocument();
866 DocumentPtr aDoc = aMgr->moduleDocument();
867 QModelIndex aOldIndex = myDataModel->activePartTree();
868 if (aActiveDoc == aDoc) {
869 if (aOldIndex.isValid())
870 aTreeView->setExpanded(aOldIndex, false);
871 myDataModel->deactivatePart();
872 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
874 std::string aGrpName = ModelAPI_ResultPart::group();
875 for (int i = 0; i < aDoc->size(aGrpName); i++) {
876 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
877 if (aPart->partDoc() == aActiveDoc) {
878 QModelIndex aIndex = myDataModel->partIndex(aPart);
879 if (myDataModel->activatePart(aIndex)) {
880 if (aOldIndex.isValid())
881 aTreeView->setExpanded(aOldIndex, false);
882 aTreeView->setExpanded(myDataModel->activePartTree(), true);
883 aPalet.setColor(QPalette::Text, Qt::black);
889 aLabel->setPalette(aPalet);
890 aWorkshop->updateCommandStatus();
892 // Update displayed objects in order to update active color
893 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
894 QObjectPtrList aObjects = aDisplayer->displayedObjects();
895 foreach(ObjectPtr aObj, aObjects)
896 aDisplayer->redisplay(aObj, false);
897 aDisplayer->updateViewer();
901 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
903 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
905 SessionPtr aMgr = ModelAPI_Session::get();
906 if (!theIndex.isValid()) {
907 aMgr->setActiveDocument(aMgr->moduleDocument());
910 if (theIndex.column() != 0) // Use only first column
912 ObjectPtr aObj = myDataModel->object(theIndex);
913 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
914 if (!aPart.get()) { // Probably this is Feature
915 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
916 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
917 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
920 if (aPart.get()) { // if this is a part
921 if (aPart->partDoc() == aMgr->activeDocument()) {
922 aMgr->setActiveDocument(aMgr->moduleDocument());
930 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
932 // z layer is created for all started operations in order to visualize operation AIS presentation
934 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
935 if (myVisualLayerId == 0) {
936 if (myVisualLayerId == 0)
937 aViewer->AddZLayer(myVisualLayerId);
939 TColStd_SequenceOfInteger aZList;
940 aViewer->GetAllZLayers(aZList);
942 for (int i = 1; i <= aZList.Length(); i++) {
943 if (aZList(i) == myVisualLayerId) {
949 aViewer->AddZLayer(myVisualLayerId);