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 } else if (theType == "point2ddistance") {
476 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
477 aDistanceWgt->setWorkshop(aWorkshop);
478 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
480 } else if(theType == "point2dangle") {
481 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent, theWidgetApi, theParentId);
482 anAngleWgt->setWorkshop(aWorkshop);
483 anAngleWgt->setSketch(mySketchMgr->activeSketch());
485 } else if (theType == "sketch_shape_selector") {
486 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
487 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
488 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
489 aWgt = aShapeSelectorWgt;
490 } else if (theType == "sketch_multi_selector") {
491 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
492 new PartSet_WidgetMultiSelector(theParent, workshop(), theWidgetApi, theParentId);
493 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
494 aWgt = aShapeSelectorWgt;
495 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
496 aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
497 } else if (theType == "export_file_selector") {
498 aWgt = new PartSet_WidgetFileSelector(theParent, workshop(), theWidgetApi, theParentId);
504 bool PartSet_Module::deleteObjects()
506 SessionPtr aMgr = ModelAPI_Session::get();
507 // 1. check whether the delete should be processed in the module
508 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
509 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
510 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
511 if (isSketchOp || isNestedOp) {
512 // 2. find selected presentations
513 // selected objects should be collected before the current operation abort because
514 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
515 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
516 XGUI_Workshop* aWorkshop = aConnector->workshop();
517 ModuleBase_ISelection* aSel = workshop()->selection();
518 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
519 // if there are no selected objects in the viewer, that means that the selection in another
520 // place cased this method. It is necessary to return the false value to understande in above
521 // method that delete is not processed
522 if (aSelectedObj.count() == 0)
525 // avoid delete of the objects, which are not belong to the current sketch
526 // in order to do not delete results of other sketches
527 QObjectPtrList aSketchObjects;
528 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
529 for ( ; anIt != aLast; anIt++) {
530 ObjectPtr anObject = *anIt;
531 if (mySketchMgr->isObjectOfSketch(anObject))
532 aSketchObjects.append(anObject);
534 // if the selection contains only local selected presentations from other sketches,
535 // the Delete operation should not be done at all
536 if (aSketchObjects.size() == 0)
539 // the active nested sketch operation should be aborted unconditionally
541 anOperation->abort();
543 // 3. start operation
544 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
545 aMgr->startOperation(aDescription.toStdString());
547 // 4. delete features
548 // sketch feature should be skipped, only sub-features can be removed
549 // when sketch operation is active
550 std::set<FeaturePtr> anIgnoredFeatures;
551 anIgnoredFeatures.insert(mySketchMgr->activeSketch());
552 aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures);
555 aWorkshop->displayer()->updateViewer();
556 aMgr->finishOperation();
558 // Delete part with help of PartSet plugin
559 // TODO: the deleted objects has to be processed by multiselection
560 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
561 if (aObjects.size() == 1) {
562 ObjectPtr aObj = aObjects.first();
563 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
564 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
565 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
566 aMgr->startOperation(PartSetPlugin_Remove::ID());
567 FeaturePtr aFeature = aDoc->addFeature(PartSetPlugin_Remove::ID());
569 aMgr->finishOperation();
579 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
581 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
582 if (!anAIS.IsNull()) {
583 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
584 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
585 if (!aDim.IsNull()) {
586 aCtx->SetZLayer(aDim, myVisualLayerId);
588 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
590 aCtx->SetZLayer(aCons, myVisualLayerId);
595 void PartSet_Module::onViewTransformed(int theTrsfType)
597 // Set length of arrows constant in pixel size
598 // if the operation is panning or rotate or panglobal then do nothing
599 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
602 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
603 //Handle(V3d_View) aView = aViewer->activeView();
605 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
606 XGUI_Workshop* aWorkshop = aConnector->workshop();
607 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
608 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
610 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
611 Handle(V3d_View) aView;
613 for (aV3dViewer->InitDefinedViews();
614 aV3dViewer->MoreDefinedViews();
615 aV3dViewer->NextDefinedViews()) {
616 Handle(V3d_View) aV = aV3dViewer->DefinedView();
617 double aS = aV->Scale();
625 double aLen = aView->Convert(20);
627 SketcherPrs_Tools::setArrowSize(aLen);
628 bool isModified = false;
629 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
630 foreach (AISObjectPtr aAIS, aPrsList) {
631 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
633 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
634 if (!aDim.IsNull()) {
635 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
636 aContext->Redisplay(aDim, false);
641 aDisplayer->updateViewer();
645 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
647 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
649 QLineEdit* aLabel = aOB->activeDocLabel();
650 QPalette aPalet = aLabel->palette();
651 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
652 aLabel->setPalette(aPalet);
653 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
654 myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&)));
659 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
661 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
662 int aSelected = aObjects.size();
663 SessionPtr aMgr = ModelAPI_Session::get();
664 if (aSelected == 1) {
665 bool hasResult = false;
666 bool hasFeature = false;
667 bool hasParameter = false;
668 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter);
670 ObjectPtr aObject = aObjects.first();
672 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
673 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
674 bool isPart = aPart.get() ||
675 (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
677 DocumentPtr aPartDoc;
679 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
681 if (aPart.get()) // this may be null is Part feature is disabled
682 aPartDoc = aPart->partDoc();
683 if (aMgr->activeDocument() == aPartDoc)
684 theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
686 theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
687 } else if (aObject->document() == aMgr->activeDocument()) {
688 if (hasParameter || hasFeature)
689 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
691 } else { // If feature is 0 the it means that selected root object (document)
692 if (aMgr->activeDocument() != aMgr->moduleDocument())
693 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
695 } else if (aSelected == 0) {
696 // if there is no selection then it means that upper label is selected
697 QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
698 if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
699 if (aMgr->activeDocument() != aMgr->moduleDocument())
700 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
704 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
706 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
707 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
708 XGUI_Workshop* aWorkshop = aConnector->workshop();
709 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
710 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
711 QPalette aPalet = aLabel->palette();
713 SessionPtr aMgr = ModelAPI_Session::get();
714 DocumentPtr aActiveDoc = aMgr->activeDocument();
715 DocumentPtr aDoc = aMgr->moduleDocument();
716 QModelIndex aOldIndex = myDataModel->activePartTree();
717 if (aActiveDoc == aDoc) {
718 if (aOldIndex.isValid())
719 aTreeView->setExpanded(aOldIndex, false);
720 myDataModel->deactivatePart();
721 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
723 std::string aGrpName = ModelAPI_ResultPart::group();
724 for (int i = 0; i < aDoc->size(aGrpName); i++) {
725 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
726 if (aPart->partDoc() == aActiveDoc) {
727 QModelIndex aIndex = myDataModel->partIndex(aPart);
728 if (myDataModel->activatePart(aIndex)) {
729 aTreeView->setExpanded(aOldIndex, false);
730 aTreeView->setExpanded(myDataModel->activePartTree(), true);
731 aPalet.setColor(QPalette::Text, Qt::black);
737 aLabel->setPalette(aPalet);
738 aWorkshop->updateCommandStatus();
740 // Update displayed objects in order to update active color
741 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
742 QObjectPtrList aObjects = aDisplayer->displayedObjects();
743 foreach(ObjectPtr aObj, aObjects)
744 aDisplayer->redisplay(aObj, false);
745 aDisplayer->updateViewer();