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_SketcherMgr.h"
15 #include "PartSet_MenuMgr.h"
17 #include <PartSetPlugin_Remove.h>
18 #include <PartSetPlugin_Part.h>
20 #include <ModuleBase_Operation.h>
21 #include <ModuleBase_IViewer.h>
22 #include <ModuleBase_IViewWindow.h>
23 #include <ModuleBase_IPropertyPanel.h>
24 #include <ModuleBase_WidgetEditor.h>
25 #include <ModuleBase_FilterFactory.h>
26 #include <ModuleBase_Tools.h>
27 #include <GeomValidators_ShapeType.h>
29 #include <GeomValidators_Face.h>
30 #include <GeomValidators_ConstructionComposite.h>
33 #include <ModelAPI_Object.h>
34 #include <ModelAPI_Events.h>
35 #include <ModelAPI_Validator.h>
36 #include <ModelAPI_Data.h>
37 #include <ModelAPI_Session.h>
38 #include <ModelAPI_ShapeValidator.h>
40 #include <GeomDataAPI_Point2D.h>
41 #include <GeomDataAPI_Point.h>
42 #include <GeomDataAPI_Dir.h>
44 #include <XGUI_Displayer.h>
45 #include <XGUI_Workshop.h>
46 #include <XGUI_OperationMgr.h>
47 #include <XGUI_PropertyPanel.h>
48 #include <XGUI_ModuleConnector.h>
49 #include <XGUI_ContextMenuMgr.h>
50 #include <XGUI_Tools.h>
51 #include <XGUI_ObjectsBrowser.h>
53 #include <SketchPlugin_Feature.h>
54 #include <SketchPlugin_Sketch.h>
55 #include <SketchPlugin_Line.h>
56 #include <SketchPlugin_Arc.h>
57 #include <SketchPlugin_Circle.h>
58 #include <SketchPlugin_Point.h>
59 #include <SketchPlugin_ConstraintLength.h>
60 #include <SketchPlugin_ConstraintDistance.h>
61 #include <SketchPlugin_ConstraintParallel.h>
62 #include <SketchPlugin_ConstraintPerpendicular.h>
63 #include <SketchPlugin_ConstraintRadius.h>
65 #include <SketcherPrs_SymbolPrs.h>
66 #include <SketcherPrs_Tools.h>
68 #include <Events_Loop.h>
69 #include <Config_PropManager.h>
70 #include <Config_Keywords.h>
72 #include <StdSelect_TypeOfFace.hxx>
73 #include <TopoDS_Vertex.hxx>
75 #include <TopoDS_Shape.hxx>
76 #include <BRep_Tool.hxx>
77 #include <AIS_Dimension.hxx>
80 #include <QMouseEvent>
83 #include <QApplication>
84 #include <QMessageBox>
85 #include <QMainWindow>
88 #include <GeomAlgoAPI_FaceBuilder.h>
89 #include <GeomDataAPI_Dir.h>
97 /*!Create and return new instance of XGUI_Module*/
98 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
100 return new PartSet_Module(theWshop);
103 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
104 : ModuleBase_IModule(theWshop),
105 myRestartingMode(RM_None), myVisualLayerId(0)
107 mySketchMgr = new PartSet_SketcherMgr(this);
108 myDataModel = new PartSet_DocumentDataModel(this);
110 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
111 XGUI_Workshop* aWorkshop = aConnector->workshop();
113 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
114 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
115 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
116 this, SLOT(onOperationActivatedByPreselection()));
118 ModuleBase_IViewer* aViewer = theWshop->viewer();
119 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
120 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
121 connect(aViewer, SIGNAL(viewTransformed(int)),
122 SLOT(onViewTransformed(int)));
124 myMenuMgr = new PartSet_MenuMgr(this);
126 Events_Loop* aLoop = Events_Loop::loop();
127 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
130 PartSet_Module::~PartSet_Module()
132 if (!myDocumentShapeFilter.IsNull())
133 myDocumentShapeFilter.Nullify();
136 void PartSet_Module::registerValidators()
138 //Registering of validators
139 SessionPtr aMgr = ModelAPI_Session::get();
140 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
141 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
142 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
143 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
144 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
145 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
146 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
147 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
148 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
149 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
150 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
152 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
153 aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
155 aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
156 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
158 aFactory->registerValidator("GeomValidators_ConstructionComposite",
159 new GeomValidators_ConstructionComposite);
161 aFactory->registerValidator("PartSet_SketchEntityValidator",
162 new PartSet_SketchEntityValidator);
164 aFactory->registerValidator("PartSet_SameTypeAttr",
165 new PartSet_SameTypeAttrValidator);
168 void PartSet_Module::registerFilters()
170 //Registering of selection filters
171 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
172 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
175 void PartSet_Module::registerProperties()
177 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
179 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
180 Config_Prop::Integer, SKETCH_WIDTH);
183 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
185 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
186 mySketchMgr->commitNestedSketch(theOperation);
189 if (theOperation->isEditOperation())
191 // the selection is cleared after commit the create operation
192 // in order to do not use the same selected objects in the restarted operation
193 // for common behaviour, the selection is cleared even if the operation is not restarted
194 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
195 if (!aContext.IsNull())
196 aContext->ClearSelected();
198 /// Restart sketcher operations automatically
199 FeaturePtr aFeature = theOperation->feature();
200 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
201 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
202 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
203 myRestartingMode == RM_EmptyFeatureUsed)) {
204 myLastOperationId = theOperation->id();
205 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
207 launchOperation(myLastOperationId);
209 breakOperationSequence();
212 void PartSet_Module::breakOperationSequence()
214 myLastOperationId = "";
215 myLastFeature = FeaturePtr();
216 myRestartingMode = RM_None;
219 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
221 breakOperationSequence();
224 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
226 // Install the document filter before any other filter
227 if (myDocumentShapeFilter.IsNull())
228 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
229 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
231 ModuleBase_IModule::sendOperation(theOperation);
234 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
236 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
237 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
238 aViewer->AddZLayer(myVisualLayerId);
239 mySketchMgr->startSketch(theOperation);
241 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
242 mySketchMgr->startNestedSketch(theOperation);
246 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
248 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
249 mySketchMgr->stopSketch(theOperation);
250 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
251 aViewer->RemoveZLayer(myVisualLayerId);
254 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
255 mySketchMgr->stopNestedSketch(theOperation);
257 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
260 ModuleBase_Operation* PartSet_Module::currentOperation() const
262 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
263 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
264 return anOpMgr->currentOperation();
267 bool PartSet_Module::canUndo() const
269 bool aCanUndo = false;
270 SessionPtr aMgr = ModelAPI_Session::get();
271 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
272 aCanUndo = !aMgr->isOperation();
273 if (!aCanUndo) // check the enable state additionally by sketch manager
274 aCanUndo = aMgr->canUndo();
279 bool PartSet_Module::canRedo() const
281 bool aCanRedo = false;
282 SessionPtr aMgr = ModelAPI_Session::get();
283 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
284 aCanRedo = !aMgr->isOperation();
285 if (!aCanRedo) // check the enable state additionally by sketch manager
286 aCanRedo = aMgr->canRedo();
291 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
293 // the sketch manager put the restriction to the objects display
294 return mySketchMgr->canDisplayObject(theObject);
298 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
300 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
303 void PartSet_Module::activeSelectionModes(QIntList& theModes)
306 if (mySketchMgr->activeSketch().get())
307 PartSet_SketcherMgr::sketchSelectionModes(theModes);
310 bool PartSet_Module::isMouseOverWindow()
312 return mySketchMgr->isMouseOverWindow();
315 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
317 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
318 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
319 // we have to manually activate the sketch label in edit mode
320 aPanel->activateWidget(aPanel->modelWidgets().first());
324 // Restart last operation type
325 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
326 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
327 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
328 // Initialise new line with first point equal to end of previous
329 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
331 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
332 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
333 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
335 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
336 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
337 aWgt->attributeID(), aPoint->x(), aPoint->y());
338 aPanel->activateNextWidget(aPnt2dWgt);
343 // Start editing constraint
344 if (theOperation->isEditOperation()) {
345 // TODO: #391 - to be removed
346 std::string aId = theOperation->id().toStdString();
347 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
348 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
349 // Find and activate widget for management of point for dimension line position
350 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
351 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
352 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
354 aPanel->activateWidget(aPntWgt);
364 void PartSet_Module::onSelectionChanged()
366 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
370 bool isSketcherOp = false;
371 // An edit operation is enable only if the current opeation is the sketch operation
372 if (mySketchMgr->activeSketch()) {
373 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
374 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
377 // Editing of constraints can be done on selection
378 ModuleBase_ISelection* aSelect = myWorkshop->selection();
379 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
380 if (aSelected.size() == 1) {
381 ModuleBase_ViewerPrs aPrs = aSelected.first();
382 ObjectPtr aObject = aPrs.object();
383 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
385 std::string aId = aFeature->getKind();
386 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
387 (aId == SketchPlugin_ConstraintLength::ID()) ||
388 (aId == SketchPlugin_ConstraintDistance::ID())) {
389 editFeature(aFeature);
396 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
398 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
399 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
400 anOpMgr->onKeyReleased(theEvent);
403 void PartSet_Module::onEnterReleased()
405 myRestartingMode = RM_EmptyFeatureUsed;
408 void PartSet_Module::onOperationActivatedByPreselection()
410 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
411 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
412 // Set final definitions if they are necessary
413 //propertyPanelDefined(aOperation);
415 /// Commit sketcher operations automatically
416 anOperation->commit();
420 void PartSet_Module::onNoMoreWidgets()
422 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
424 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
425 if (myRestartingMode != RM_Forbided)
426 myRestartingMode = RM_LastFeatureUsed;
427 anOperation->commit();
432 void PartSet_Module::onVertexSelected()
434 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
435 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
436 /// If last line finished on vertex the lines creation sequence has to be break
437 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
438 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
439 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
440 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
441 bool aFoundWidget = false;
442 bool aFoundObligatory = false;
443 for (; anIt != aLast && !aFoundObligatory; anIt++) {
445 aFoundWidget = *anIt == anActiveWidget;
447 aFoundObligatory = (*anIt)->isObligatory();
449 if (!aFoundObligatory)
450 myRestartingMode = RM_Forbided;
454 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
455 Config_WidgetAPI* theWidgetApi, std::string theParentId)
457 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
458 XGUI_Workshop* aWorkshop = aConnector->workshop();
459 ModuleBase_ModelWidget* aWgt = NULL;
460 if (theType == "sketch-start-label") {
461 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent,
462 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
463 aLabelWgt->setWorkshop(aWorkshop);
464 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
465 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
466 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
467 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
469 } else if (theType == "sketch-2dpoint_selector") {
470 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
471 aPointWgt->setWorkshop(aWorkshop);
472 aPointWgt->setSketch(mySketchMgr->activeSketch());
473 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
475 } if (theType == "point2ddistance") {
476 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
477 aDistanceWgt->setWorkshop(aWorkshop);
478 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
480 } if(theType == "point2dangle") {
481 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent, theWidgetApi, theParentId);
482 anAngleWgt->setWorkshop(aWorkshop);
483 anAngleWgt->setSketch(mySketchMgr->activeSketch());
486 if (theType == "sketch_shape_selector") {
487 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
488 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
489 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
490 aWgt = aShapeSelectorWgt;
491 } if (theType == "sketch_multi_selector") {
492 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
493 new PartSet_WidgetMultiSelector(theParent, workshop(), theWidgetApi, theParentId);
494 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
495 aWgt = aShapeSelectorWgt;
497 if (theType == WDG_DOUBLEVALUE_EDITOR) {
498 aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
499 } else if (theType == "export_file_selector") {
500 aWgt = new PartSet_WidgetFileSelector(theParent, workshop(), theWidgetApi, theParentId);
506 bool PartSet_Module::deleteObjects()
508 SessionPtr aMgr = ModelAPI_Session::get();
509 // 1. check whether the delete should be processed in the module
510 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
511 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
512 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
513 if (isSketchOp && isNestedOp) {
514 // 2. find selected presentations
515 // selected objects should be collected before the current operation abort because
516 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
517 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
518 XGUI_Workshop* aWorkshop = aConnector->workshop();
519 ModuleBase_ISelection* aSel = workshop()->selection();
520 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
521 // if there are no selected objects in the viewer, that means that the selection in another
522 // place cased this method. It is necessary to return the false value to understande in above
523 // method that delete is not processed
524 if (aSelectedObj.count() == 0)
527 // avoid delete of the objects, which are not belong to the current sketch
528 // in order to do not delete results of other sketches
529 QObjectPtrList aSketchObjects;
530 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
531 for ( ; anIt != aLast; anIt++) {
532 ObjectPtr anObject = *anIt;
533 if (mySketchMgr->isObjectOfSketch(anObject))
534 aSketchObjects.append(anObject);
536 // if the selection contains only local selected presentations from other sketches,
537 // the Delete operation should not be done at all
538 if (aSketchObjects.size() == 0)
541 // the active nested sketch operation should be aborted unconditionally
543 anOperation->abort();
545 // 3. start operation
546 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
547 aMgr->startOperation(aDescription.toStdString());
549 // 4. delete features
550 // sketch feature should be skipped, only sub-features can be removed
551 // when sketch operation is active
552 std::set<FeaturePtr> anIgnoredFeatures;
553 anIgnoredFeatures.insert(mySketchMgr->activeSketch());
554 aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures);
557 aWorkshop->displayer()->updateViewer();
558 aMgr->finishOperation();
560 // Delete part with help of PartSet plugin
561 // TODO: the deleted objects has to be processed by multiselection
562 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
563 if (aObjects.size() == 1) {
564 ObjectPtr aObj = aObjects.first();
565 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
566 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
567 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
568 aMgr->startOperation(PartSetPlugin_Remove::ID());
569 FeaturePtr aFeature = aDoc->addFeature(PartSetPlugin_Remove::ID());
571 aMgr->finishOperation();
581 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
583 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
584 if (!anAIS.IsNull()) {
585 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
586 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
587 if (!aDim.IsNull()) {
588 aCtx->SetZLayer(aDim, myVisualLayerId);
590 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
592 aCtx->SetZLayer(aCons, myVisualLayerId);
597 void PartSet_Module::onViewTransformed(int theTrsfType)
599 // Set length of arrows constant in pixel size
600 // if the operation is panning or rotate or panglobal then do nothing
601 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
604 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
605 //Handle(V3d_View) aView = aViewer->activeView();
607 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
608 XGUI_Workshop* aWorkshop = aConnector->workshop();
609 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
610 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
612 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
613 Handle(V3d_View) aView;
615 for (aV3dViewer->InitDefinedViews();
616 aV3dViewer->MoreDefinedViews();
617 aV3dViewer->NextDefinedViews()) {
618 Handle(V3d_View) aV = aV3dViewer->DefinedView();
619 double aS = aV->Scale();
627 double aLen = aView->Convert(20);
629 SketcherPrs_Tools::setArrowSize(aLen);
630 bool isModified = false;
631 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
632 foreach (AISObjectPtr aAIS, aPrsList) {
633 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
635 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
636 if (!aDim.IsNull()) {
637 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
638 aContext->Redisplay(aDim, false);
643 aDisplayer->updateViewer();
647 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
649 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
651 QLineEdit* aLabel = aOB->activeDocLabel();
652 QPalette aPalet = aLabel->palette();
653 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
654 aLabel->setPalette(aPalet);
655 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
656 myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&)));
661 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
663 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
664 int aSelected = aObjects.size();
665 SessionPtr aMgr = ModelAPI_Session::get();
666 if (aSelected == 1) {
667 bool hasResult = false;
668 bool hasFeature = false;
669 bool hasParameter = false;
670 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter);
672 ObjectPtr aObject = aObjects.first();
674 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
675 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
676 bool isPart = aPart.get() ||
677 (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
679 DocumentPtr aPartDoc;
681 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
683 if (aPart.get()) // this may be null is Part feature is disabled
685 if (aMgr->activeDocument() == aPartDoc)
686 theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
688 theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
689 } else if (aObject->document() == aMgr->activeDocument()) {
690 if (hasParameter || hasFeature)
691 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
693 } else { // If feature is 0 the it means that selected root object (document)
694 if (aMgr->activeDocument() != aMgr->moduleDocument())
695 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
697 } else if (aSelected == 0) {
698 // if there is no selection then it means that upper label is selected
699 QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
700 if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
701 if (aMgr->activeDocument() != aMgr->moduleDocument())
702 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
706 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
708 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
709 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
710 XGUI_Workshop* aWorkshop = aConnector->workshop();
711 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
712 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
713 QPalette aPalet = aLabel->palette();
715 SessionPtr aMgr = ModelAPI_Session::get();
716 DocumentPtr aActiveDoc = aMgr->activeDocument();
717 DocumentPtr aDoc = aMgr->moduleDocument();
718 QModelIndex aOldIndex = myDataModel->activePartTree();
719 if (aActiveDoc == aDoc) {
720 if (aOldIndex.isValid())
721 aTreeView->setExpanded(aOldIndex, false);
722 myDataModel->deactivatePart();
723 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
725 std::string aGrpName = ModelAPI_ResultPart::group();
726 for (int i = 0; i < aDoc->size(aGrpName); i++) {
727 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
728 if (aPart->partDoc() == aActiveDoc) {
729 QModelIndex aIndex = myDataModel->partIndex(aPart);
730 if (myDataModel->activatePart(aIndex)) {
731 aTreeView->setExpanded(aOldIndex, false);
732 aTreeView->setExpanded(myDataModel->activePartTree(), true);
733 aPalet.setColor(QPalette::Text, Qt::black);
739 aLabel->setPalette(aPalet);