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_WidgetShapeSelector.h"
10 #include "PartSet_WidgetPoint2dAngle.h"
11 #include "PartSet_WidgetMultiSelector.h"
12 #include "PartSet_WidgetEditor.h"
13 #include "PartSet_WidgetFileSelector.h"
14 #include "PartSet_WidgetSketchCreator.h"
15 #include "PartSet_SketcherMgr.h"
16 #include "PartSet_MenuMgr.h"
18 #include "PartSet_Filters.h"
19 #include "PartSet_FilterInfinite.h"
21 #include <PartSetPlugin_Remove.h>
22 #include <PartSetPlugin_Part.h>
24 #include <ModuleBase_Operation.h>
25 #include <ModuleBase_IViewer.h>
26 #include <ModuleBase_IViewWindow.h>
27 #include <ModuleBase_IPropertyPanel.h>
28 #include <ModuleBase_WidgetEditor.h>
29 #include <ModuleBase_FilterFactory.h>
30 #include <ModuleBase_Tools.h>
31 #include <GeomValidators_ShapeType.h>
33 #include <GeomValidators_Face.h>
34 #include <GeomValidators_ConstructionComposite.h>
35 #include <GeomValidators_ZeroOffset.h>
36 #include <GeomValidators_BooleanArguments.h>
39 #include <ModelAPI_Object.h>
40 #include <ModelAPI_Events.h>
41 #include <ModelAPI_Validator.h>
42 #include <ModelAPI_Data.h>
43 #include <ModelAPI_Session.h>
44 #include <ModelAPI_ShapeValidator.h>
46 #include <GeomDataAPI_Point2D.h>
47 #include <GeomDataAPI_Point.h>
48 #include <GeomDataAPI_Dir.h>
50 #include <XGUI_Displayer.h>
51 #include <XGUI_Workshop.h>
52 #include <XGUI_OperationMgr.h>
53 #include <XGUI_PropertyPanel.h>
54 #include <XGUI_ModuleConnector.h>
55 #include <XGUI_ContextMenuMgr.h>
56 #include <XGUI_Tools.h>
57 #include <XGUI_ObjectsBrowser.h>
58 #include <XGUI_SelectionMgr.h>
60 #include <SketchPlugin_Feature.h>
61 #include <SketchPlugin_Sketch.h>
62 #include <SketchPlugin_Line.h>
63 #include <SketchPlugin_Arc.h>
64 #include <SketchPlugin_Circle.h>
65 #include <SketchPlugin_Point.h>
66 #include <SketchPlugin_ConstraintLength.h>
67 #include <SketchPlugin_ConstraintDistance.h>
68 #include <SketchPlugin_ConstraintParallel.h>
69 #include <SketchPlugin_ConstraintPerpendicular.h>
70 #include <SketchPlugin_ConstraintRadius.h>
72 #include <SketcherPrs_SymbolPrs.h>
73 #include <SketcherPrs_Tools.h>
75 #include <Events_Loop.h>
76 #include <Config_PropManager.h>
77 #include <Config_Keywords.h>
79 #include <StdSelect_TypeOfFace.hxx>
80 #include <TopoDS_Vertex.hxx>
82 #include <TopoDS_Shape.hxx>
83 #include <BRep_Tool.hxx>
84 #include <AIS_Dimension.hxx>
87 #include <QMouseEvent>
90 #include <QApplication>
91 #include <QMessageBox>
92 #include <QMainWindow>
95 #include <GeomAlgoAPI_FaceBuilder.h>
96 #include <GeomDataAPI_Dir.h>
98 #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 myRestartingMode(RM_None), myVisualLayerId(0)
116 mySketchMgr = new PartSet_SketcherMgr(this);
117 myDataModel = new PartSet_DocumentDataModel(this);
119 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
120 XGUI_Workshop* aWorkshop = aConnector->workshop();
122 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
123 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
124 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
125 this, SLOT(onOperationActivatedByPreselection()));
127 ModuleBase_IViewer* aViewer = theWshop->viewer();
128 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
129 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
130 connect(aViewer, SIGNAL(viewTransformed(int)),
131 SLOT(onViewTransformed(int)));
133 myMenuMgr = new PartSet_MenuMgr(this);
135 Events_Loop* aLoop = Events_Loop::loop();
136 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
138 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
139 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
142 PartSet_Module::~PartSet_Module()
144 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
145 for (; aIt.More(); aIt.Next()) {
146 Handle(SelectMgr_Filter) aFilter = aIt.Value();
147 if (!aFilter.IsNull())
152 void PartSet_Module::activateSelectionFilters()
154 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
155 for (; aIt.More(); aIt.Next()) {
156 Handle(SelectMgr_Filter) aFilter = aIt.Value();
157 if (!aFilter.IsNull())
158 myWorkshop->viewer()->addSelectionFilter(aFilter);
162 void PartSet_Module::deactivateSelectionFilters()
164 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
165 for (; aIt.More(); aIt.Next()) {
166 Handle(SelectMgr_Filter) aFilter = aIt.Value();
167 if (!aFilter.IsNull())
168 myWorkshop->viewer()->removeSelectionFilter(aFilter);
172 void PartSet_Module::registerValidators()
174 //Registering of validators
175 SessionPtr aMgr = ModelAPI_Session::get();
176 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
177 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
178 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
179 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
180 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
181 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
182 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
183 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
184 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
185 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
186 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
188 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
189 aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
191 aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
192 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
194 aFactory->registerValidator("GeomValidators_ConstructionComposite",
195 new GeomValidators_ConstructionComposite);
197 aFactory->registerValidator("GeomValidators_ZeroOffset",
198 new GeomValidators_ZeroOffset);
200 aFactory->registerValidator("GeomValidators_BooleanArguments",
201 new GeomValidators_BooleanArguments);
203 aFactory->registerValidator("PartSet_SketchEntityValidator",
204 new PartSet_SketchEntityValidator);
206 aFactory->registerValidator("PartSet_SameTypeAttr",
207 new PartSet_SameTypeAttrValidator);
210 void PartSet_Module::registerFilters()
212 //Registering of selection filters
213 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
214 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
217 void PartSet_Module::registerProperties()
219 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
221 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
222 Config_Prop::Integer, SKETCH_WIDTH);
225 void PartSet_Module::onOperationCommitted(ModuleBase_Operation* theOperation)
227 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
228 mySketchMgr->commitNestedSketch(theOperation);
231 if (theOperation->isEditOperation())
233 // the selection is cleared after commit the create operation
234 // in order to do not use the same selected objects in the restarted operation
235 // for common behaviour, the selection is cleared even if the operation is not restarted
236 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
237 XGUI_Workshop* aWorkshop = aConnector->workshop();
238 aWorkshop->selector()->clearSelection();
240 /// Restart sketcher operations automatically
241 FeaturePtr aFeature = theOperation->feature();
242 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
243 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
244 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
245 myRestartingMode == RM_EmptyFeatureUsed)) {
246 myLastOperationId = theOperation->id();
247 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
249 launchOperation(myLastOperationId);
251 breakOperationSequence();
254 void PartSet_Module::breakOperationSequence()
256 myLastOperationId = "";
257 myLastFeature = FeaturePtr();
258 myRestartingMode = RM_None;
261 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
263 breakOperationSequence();
266 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
268 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
269 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
270 aViewer->AddZLayer(myVisualLayerId);
271 mySketchMgr->startSketch(theOperation);
273 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
274 mySketchMgr->startNestedSketch(theOperation);
278 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
280 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
281 mySketchMgr->stopSketch(theOperation);
282 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
283 aViewer->RemoveZLayer(myVisualLayerId);
286 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
287 mySketchMgr->stopNestedSketch(theOperation);
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::canCommitOperation() const
324 return mySketchMgr->canCommitOperation();
327 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
329 // the sketch manager put the restriction to the objects display
330 return mySketchMgr->canDisplayObject(theObject);
333 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
335 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
337 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
338 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
339 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
340 if (isSketchOp || isNestedOp) {
341 // in active sketch operation it is possible to activate operation object in selection
342 // in the edit operation, e.g. points of the line can be moved when the line is edited
343 aCanActivate = aCanActivate || anOperation->isEditOperation();
348 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
350 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
353 void PartSet_Module::activeSelectionModes(QIntList& theModes)
356 if (mySketchMgr->activeSketch().get())
357 PartSet_SketcherMgr::sketchSelectionModes(theModes);
360 bool PartSet_Module::isMouseOverWindow()
362 return mySketchMgr->isMouseOverWindow();
365 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
367 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
368 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
369 // we have to manually activate the sketch label in edit mode
370 aPanel->activateWidget(aPanel->modelWidgets().first());
374 // Restart last operation type
375 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
376 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
377 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
378 // Initialise new line with first point equal to end of previous
379 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
381 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
382 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
383 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
385 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
386 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
387 aWgt->attributeID(), aPoint->x(), aPoint->y());
388 aPanel->activateNextWidget(aPnt2dWgt);
396 void PartSet_Module::onSelectionChanged()
398 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
402 bool isSketcherOp = false;
403 // An edit operation is enable only if the current opeation is the sketch operation
404 if (mySketchMgr->activeSketch()) {
405 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
406 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
409 // Editing of constraints can be done on selection
410 ModuleBase_ISelection* aSelect = myWorkshop->selection();
411 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
412 if (aSelected.size() == 1) {
413 ModuleBase_ViewerPrs aPrs = aSelected.first();
414 ObjectPtr aObject = aPrs.object();
415 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
417 std::string aId = aFeature->getKind();
418 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
419 (aId == SketchPlugin_ConstraintLength::ID()) ||
420 (aId == SketchPlugin_ConstraintDistance::ID())) {
421 editFeature(aFeature);
428 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
430 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
431 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
432 anOpMgr->onKeyReleased(theEvent);
435 void PartSet_Module::onEnterReleased()
437 myRestartingMode = RM_EmptyFeatureUsed;
440 void PartSet_Module::onOperationActivatedByPreselection()
442 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
443 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
444 // Set final definitions if they are necessary
445 //propertyPanelDefined(aOperation);
447 /// Commit sketcher operations automatically
448 anOperation->commit();
452 void PartSet_Module::onNoMoreWidgets()
454 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
456 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
457 if (myRestartingMode != RM_Forbided)
458 myRestartingMode = RM_LastFeatureUsed;
459 anOperation->commit();
464 void PartSet_Module::onVertexSelected()
466 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
467 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
468 /// If last line finished on vertex the lines creation sequence has to be break
469 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
470 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
471 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
472 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
473 bool aFoundWidget = false;
474 bool aFoundObligatory = false;
475 for (; anIt != aLast && !aFoundObligatory; anIt++) {
477 aFoundWidget = *anIt == anActiveWidget;
479 aFoundObligatory = (*anIt)->isObligatory();
481 if (!aFoundObligatory)
482 myRestartingMode = RM_Forbided;
486 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
487 Config_WidgetAPI* theWidgetApi, std::string theParentId)
489 ModuleBase_IWorkshop* aWorkshop = workshop();
490 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
491 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
492 ModuleBase_ModelWidget* aWgt = NULL;
493 if (theType == "sketch-start-label") {
494 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent,
495 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
496 aLabelWgt->setWorkshop(aXUIWorkshop);
497 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
498 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
499 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
500 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
502 } else if (theType == "sketch-2dpoint_selector") {
503 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
504 theWidgetApi, theParentId);
505 aPointWgt->setSketch(mySketchMgr->activeSketch());
506 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
508 } else if (theType == "point2ddistance") {
509 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
510 aWorkshop, theWidgetApi, theParentId);
511 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
513 } else if(theType == "point2dangle") {
514 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
515 aWorkshop, theWidgetApi, theParentId);
516 anAngleWgt->setSketch(mySketchMgr->activeSketch());
518 } else if (theType == "sketch_shape_selector") {
519 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
520 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
521 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
522 aWgt = aShapeSelectorWgt;
523 } else if (theType == "sketch_multi_selector") {
524 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
525 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
526 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
527 aWgt = aShapeSelectorWgt;
528 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
529 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
530 } else if (theType == "export_file_selector") {
531 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
532 } else if (theType == "sketch_launcher") {
533 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
539 bool PartSet_Module::deleteObjects()
541 SessionPtr aMgr = ModelAPI_Session::get();
542 // 1. check whether the delete should be processed in the module
543 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
544 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
545 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
546 if (isSketchOp || isNestedOp) {
547 // 2. find selected presentations
548 // selected objects should be collected before the current operation abort because
549 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
550 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
551 XGUI_Workshop* aWorkshop = aConnector->workshop();
552 ModuleBase_ISelection* aSel = workshop()->selection();
553 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
554 // if there are no selected objects in the viewer, that means that the selection in another
555 // place cased this method. It is necessary to return the false value to understande in above
556 // method that delete is not processed
557 if (aSelectedObj.count() == 0)
560 // avoid delete of the objects, which are not belong to the current sketch
561 // in order to do not delete results of other sketches
562 QObjectPtrList aSketchObjects;
563 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
564 for ( ; anIt != aLast; anIt++) {
565 ObjectPtr anObject = *anIt;
566 if (mySketchMgr->isObjectOfSketch(anObject)) {
567 // sketch feature should be used in this list because workshop deletes features only
568 // results are skipped
569 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
570 aSketchObjects.append(aSketchFeature);
573 // if the selection contains only local selected presentations from other sketches,
574 // the Delete operation should not be done at all
575 if (aSketchObjects.size() == 0)
578 // the active nested sketch operation should be aborted unconditionally
580 anOperation->abort();
582 // 3. start operation
583 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
584 aMgr->startOperation(aDescription.toStdString());
586 // 4. delete features
587 // sketch feature should be skipped, only sub-features can be removed
588 // when sketch operation is active
589 std::set<FeaturePtr> anIgnoredFeatures;
590 anIgnoredFeatures.insert(mySketchMgr->activeSketch());
591 aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures);
594 aWorkshop->displayer()->updateViewer();
595 aMgr->finishOperation();
597 bool isPartRemoved = false;
598 // Delete part with help of PartSet plugin
599 // TODO: the deleted objects has to be processed by multiselection
600 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
601 if (aObjects.size() == 1) {
602 ObjectPtr aObj = aObjects.first();
603 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
604 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
605 // Remove feature should be created in the document of the part results
606 ResultPtr aPartResult = aFeature->firstResult();
607 if (aPartResult.get()) {
608 std::shared_ptr<ModelAPI_ResultPart> aPart =
609 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
610 DocumentPtr aPartDoc = aPart->partDoc();
611 if (aPartDoc.get()) {
612 aMgr->startOperation(PartSetPlugin_Remove::ID());
613 FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
615 aMgr->finishOperation();
616 isPartRemoved = true;
621 return isPartRemoved;
626 void PartSet_Module::onFeatureTriggered()
628 SessionPtr aMgr = ModelAPI_Session::get();
629 // 1. check whether the delete should be processed in the module
630 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
631 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
633 // in case if in the viewer nothing is displayed, the create operation should not be
634 // comitted even if all values of the feature are initialized
635 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
636 QAction* aCmd = dynamic_cast<QAction*>(sender());
637 //Do nothing on uncheck
638 if (aCmd->isCheckable() && !aCmd->isChecked())
641 // the action information should be saved before the operation is aborted
642 // because this abort leads to update command status, which unchecks this action
643 anOperation->abort();
645 launchOperation(aCmd->data().toString());
648 ModuleBase_IModule::onFeatureTriggered();
651 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
653 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
654 if (!anAIS.IsNull()) {
655 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
656 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
657 if (!aDim.IsNull()) {
658 aCtx->SetZLayer(aDim, myVisualLayerId);
660 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
662 aCtx->SetZLayer(aCons, myVisualLayerId);
667 void PartSet_Module::onViewTransformed(int theTrsfType)
669 // Set length of arrows constant in pixel size
670 // if the operation is panning or rotate or panglobal then do nothing
671 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
674 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
675 //Handle(V3d_View) aView = aViewer->activeView();
677 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
678 XGUI_Workshop* aWorkshop = aConnector->workshop();
679 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
680 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
682 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
683 Handle(V3d_View) aView;
685 for (aV3dViewer->InitDefinedViews();
686 aV3dViewer->MoreDefinedViews();
687 aV3dViewer->NextDefinedViews()) {
688 Handle(V3d_View) aV = aV3dViewer->DefinedView();
689 double aS = aV->Scale();
697 double aLen = aView->Convert(20);
699 double aPrevLen = SketcherPrs_Tools::getArrowSize();
700 SketcherPrs_Tools::setArrowSize(aLen);
701 const double aPrevScale = aViewer->Scale(aViewer->activeView());
702 const double aCurScale = aViewer->activeView()->Camera()->Scale();
703 aViewer->SetScale(aViewer->activeView(), aCurScale);
704 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
705 bool isModified = false;
706 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
707 foreach (AISObjectPtr aAIS, aPrsList) {
708 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
710 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
711 if (!aDim.IsNull()) {
712 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
713 aContext->Redisplay(aDim, false);
718 aDisplayer->updateViewer();
722 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
724 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
726 QLineEdit* aLabel = aOB->activeDocLabel();
727 QPalette aPalet = aLabel->palette();
728 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
729 aLabel->setPalette(aPalet);
730 aOB->treeView()->setExpandsOnDoubleClick(false);
731 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
732 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
733 connect(aOB, SIGNAL(headerMouseDblClicked(const QModelIndex&)),
734 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
735 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
736 myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&)));
741 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
743 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
744 int aSelected = aObjects.size();
745 SessionPtr aMgr = ModelAPI_Session::get();
746 if (aSelected == 1) {
747 bool hasResult = false;
748 bool hasFeature = false;
749 bool hasParameter = false;
750 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter);
752 ObjectPtr aObject = aObjects.first();
754 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
755 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
756 bool isPart = aPart.get() ||
757 (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
759 DocumentPtr aPartDoc;
761 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
763 if (aPart.get()) // this may be null is Part feature is disabled
764 aPartDoc = aPart->partDoc();
765 if (aMgr->activeDocument() == aPartDoc)
766 theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
768 theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
769 } else if (aObject->document() == aMgr->activeDocument()) {
770 if (hasParameter || hasFeature)
771 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
773 } else { // If feature is 0 the it means that selected root object (document)
774 if (aMgr->activeDocument() != aMgr->moduleDocument())
775 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
777 } else if (aSelected == 0) {
778 // if there is no selection then it means that upper label is selected
779 QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
780 if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
781 if (aMgr->activeDocument() != aMgr->moduleDocument())
782 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
784 bool aCanDeactivate = (myWorkshop->currentOperation() == 0);
785 myMenuMgr->action("ACTIVATE_PARTSET_CMD")->setEnabled(aCanDeactivate);
786 myMenuMgr->action("DEACTIVATE_PART_CMD")->setEnabled(aCanDeactivate);
787 myMenuMgr->action("ACTIVATE_PART_CMD")->setEnabled(aCanDeactivate);
790 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
792 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
793 // Do not change activation of parts if an operation active
794 if (myWorkshop->currentOperation() && myWorkshop->currentOperation()->id().toStdString() != PartSetPlugin_Part::ID())
796 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
797 XGUI_Workshop* aWorkshop = aConnector->workshop();
798 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
799 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
800 QPalette aPalet = aLabel->palette();
802 SessionPtr aMgr = ModelAPI_Session::get();
803 DocumentPtr aActiveDoc = aMgr->activeDocument();
804 DocumentPtr aDoc = aMgr->moduleDocument();
805 QModelIndex aOldIndex = myDataModel->activePartTree();
806 if (aActiveDoc == aDoc) {
807 if (aOldIndex.isValid())
808 aTreeView->setExpanded(aOldIndex, false);
809 myDataModel->deactivatePart();
810 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
812 std::string aGrpName = ModelAPI_ResultPart::group();
813 for (int i = 0; i < aDoc->size(aGrpName); i++) {
814 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
815 if (aPart->partDoc() == aActiveDoc) {
816 QModelIndex aIndex = myDataModel->partIndex(aPart);
817 if (myDataModel->activatePart(aIndex)) {
818 if (aOldIndex.isValid())
819 aTreeView->setExpanded(aOldIndex, false);
820 aTreeView->setExpanded(myDataModel->activePartTree(), true);
821 aPalet.setColor(QPalette::Text, Qt::black);
827 aLabel->setPalette(aPalet);
828 aWorkshop->updateCommandStatus();
830 // Update displayed objects in order to update active color
831 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
832 QObjectPtrList aObjects = aDisplayer->displayedObjects();
833 foreach(ObjectPtr aObj, aObjects)
834 aDisplayer->redisplay(aObj, false);
835 aDisplayer->updateViewer();
839 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
841 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
843 SessionPtr aMgr = ModelAPI_Session::get();
844 if (!theIndex.isValid()) {
845 aMgr->setActiveDocument(aMgr->moduleDocument());
848 if (theIndex.column() != 0) // Use only first column
850 ObjectPtr aObj = myDataModel->object(theIndex);
851 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
852 if (!aPart.get()) { // Probably this is Feature
853 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
854 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
855 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
858 if (aPart.get()) { // if this is a part
859 if (aPart->partDoc() == aMgr->activeDocument()) {
860 aMgr->setActiveDocument(aMgr->moduleDocument());