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_WidgetMultiSelector.h"
11 #include "PartSet_WidgetEditor.h"
12 #include "PartSet_SketcherMgr.h"
13 #include "PartSet_MenuMgr.h"
14 #include "PartSet_DocumentDataModel.h"
16 #include <PartSetPlugin_Remove.h>
17 #include <PartSetPlugin_Part.h>
19 #include <ModuleBase_Operation.h>
20 #include <ModuleBase_IViewer.h>
21 #include <ModuleBase_IViewWindow.h>
22 #include <ModuleBase_IPropertyPanel.h>
23 #include <ModuleBase_WidgetEditor.h>
24 #include <ModuleBase_FilterFactory.h>
25 #include <ModuleBase_Tools.h>
27 #include <GeomValidators_Edge.h>
28 #include <GeomValidators_EdgeOrVertex.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_Edge", new GeomValidators_Edge);
156 aFactory->registerValidator("GeomValidators_EdgeOrVertex",
157 new GeomValidators_EdgeOrVertex);
158 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
160 aFactory->registerValidator("GeomValidators_ConstructionComposite",
161 new GeomValidators_ConstructionComposite);
163 aFactory->registerValidator("PartSet_SketchEntityValidator",
164 new PartSet_SketchEntityValidator);
166 aFactory->registerValidator("PartSet_SameTypeAttr",
167 new PartSet_SameTypeAttrValidator);
170 void PartSet_Module::registerFilters()
172 //Registering of selection filters
173 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
174 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
177 void PartSet_Module::registerProperties()
179 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
181 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
182 Config_Prop::Integer, SKETCH_WIDTH);
185 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
187 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
188 mySketchMgr->commitNestedSketch(theOperation);
191 if (theOperation->isEditOperation())
193 // the selection is cleared after commit the create operation
194 // in order to do not use the same selected objects in the restarted operation
195 // for common behaviour, the selection is cleared even if the operation is not restarted
196 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
197 if (!aContext.IsNull())
198 aContext->ClearSelected();
200 /// Restart sketcher operations automatically
201 FeaturePtr aFeature = theOperation->feature();
202 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
203 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
204 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
205 myRestartingMode == RM_EmptyFeatureUsed)) {
206 myLastOperationId = theOperation->id();
207 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
209 launchOperation(myLastOperationId);
211 breakOperationSequence();
214 void PartSet_Module::breakOperationSequence()
216 myLastOperationId = "";
217 myLastFeature = FeaturePtr();
218 myRestartingMode = RM_None;
221 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
223 breakOperationSequence();
226 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
228 // Install the document filter before any other filter
229 if (myDocumentShapeFilter.IsNull())
230 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
231 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
233 ModuleBase_IModule::sendOperation(theOperation);
236 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
238 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
239 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
240 aViewer->AddZLayer(myVisualLayerId);
241 mySketchMgr->startSketch(theOperation);
243 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
244 mySketchMgr->startNestedSketch(theOperation);
248 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
250 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
251 mySketchMgr->stopSketch(theOperation);
252 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
253 aViewer->RemoveZLayer(myVisualLayerId);
256 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
257 mySketchMgr->stopNestedSketch(theOperation);
259 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
262 ModuleBase_Operation* PartSet_Module::currentOperation() const
264 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
265 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
266 return anOpMgr->currentOperation();
269 bool PartSet_Module::canUndo() const
271 bool aCanUndo = false;
272 SessionPtr aMgr = ModelAPI_Session::get();
273 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
274 aCanUndo = !aMgr->isOperation();
275 if (!aCanUndo) // check the enable state additionally by sketch manager
276 aCanUndo = aMgr->canUndo();
281 bool PartSet_Module::canRedo() const
283 bool aCanRedo = false;
284 SessionPtr aMgr = ModelAPI_Session::get();
285 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
286 aCanRedo = !aMgr->isOperation();
287 if (!aCanRedo) // check the enable state additionally by sketch manager
288 aCanRedo = aMgr->canRedo();
293 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
295 // the sketch manager put the restriction to the objects display
296 return mySketchMgr->canDisplayObject(theObject);
300 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
302 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
305 bool PartSet_Module::isMouseOverWindow()
307 return mySketchMgr->isMouseOverWindow();
310 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
312 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
313 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
314 // we have to manually activate the sketch label in edit mode
315 aPanel->activateWidget(aPanel->modelWidgets().first());
319 // Restart last operation type
320 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
321 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
322 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
323 // Initialise new line with first point equal to end of previous
324 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
326 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
327 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
328 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
330 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
331 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
332 aWgt->attributeID(), aPoint->x(), aPoint->y());
333 aPanel->activateNextWidget(aPnt2dWgt);
338 // Start editing constraint
339 if (theOperation->isEditOperation()) {
340 // TODO: #391 - to be removed
341 std::string aId = theOperation->id().toStdString();
342 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
343 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
344 // Find and activate widget for management of point for dimension line position
345 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
346 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
347 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
349 aPanel->activateWidget(aPntWgt);
359 void PartSet_Module::onSelectionChanged()
361 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
365 bool isSketcherOp = false;
366 // An edit operation is enable only if the current opeation is the sketch operation
367 if (mySketchMgr->activeSketch()) {
368 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
369 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
372 // Editing of constraints can be done on selection
373 ModuleBase_ISelection* aSelect = myWorkshop->selection();
374 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
375 if (aSelected.size() == 1) {
376 ModuleBase_ViewerPrs aPrs = aSelected.first();
377 ObjectPtr aObject = aPrs.object();
378 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
380 std::string aId = aFeature->getKind();
381 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
382 (aId == SketchPlugin_ConstraintLength::ID()) ||
383 (aId == SketchPlugin_ConstraintDistance::ID())) {
384 editFeature(aFeature);
391 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
393 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
394 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
395 anOpMgr->onKeyReleased(theEvent);
398 void PartSet_Module::onEnterReleased()
400 myRestartingMode = RM_EmptyFeatureUsed;
403 void PartSet_Module::onOperationActivatedByPreselection()
405 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
406 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
407 // Set final definitions if they are necessary
408 //propertyPanelDefined(aOperation);
410 /// Commit sketcher operations automatically
411 anOperation->commit();
415 void PartSet_Module::onNoMoreWidgets()
417 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
419 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
420 if (myRestartingMode != RM_Forbided)
421 myRestartingMode = RM_LastFeatureUsed;
422 anOperation->commit();
427 void PartSet_Module::onVertexSelected()
429 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
430 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
431 /// If last line finished on vertex the lines creation sequence has to be break
432 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
433 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
434 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
435 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
436 bool aFoundWidget = false;
437 bool aFoundObligatory = false;
438 for (; anIt != aLast && !aFoundObligatory; anIt++) {
440 aFoundWidget = *anIt == anActiveWidget;
442 aFoundObligatory = (*anIt)->isObligatory();
444 if (!aFoundObligatory)
445 myRestartingMode = RM_Forbided;
449 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
450 Config_WidgetAPI* theWidgetApi, std::string theParentId)
452 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
453 XGUI_Workshop* aWorkshop = aConnector->workshop();
454 ModuleBase_ModelWidget* aWgt = NULL;
455 if (theType == "sketch-start-label") {
456 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent,
457 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
458 aLabelWgt->setWorkshop(aWorkshop);
459 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
460 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
461 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
462 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
464 } else if (theType == "sketch-2dpoint_selector") {
465 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
466 aPointWgt->setWorkshop(aWorkshop);
467 aPointWgt->setSketch(mySketchMgr->activeSketch());
468 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
470 } if (theType == "point2ddistance") {
471 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
472 aDistanceWgt->setWorkshop(aWorkshop);
473 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
475 } if (theType == "sketch_shape_selector") {
476 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
477 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
478 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
479 aWgt = aShapeSelectorWgt;
480 } if (theType == "sketch_multi_selector") {
481 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
482 new PartSet_WidgetMultiSelector(theParent, workshop(), theWidgetApi, theParentId);
483 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
484 aWgt = aShapeSelectorWgt;
486 if (theType == WDG_DOUBLEVALUE_EDITOR) {
487 aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
493 bool PartSet_Module::deleteObjects()
495 SessionPtr aMgr = ModelAPI_Session::get();
496 // 1. check whether the delete should be processed in the module
497 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
498 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
499 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
500 if (isSketchOp && isNestedOp) {
501 // 2. find selected presentations
502 // selected objects should be collected before the current operation abort because
503 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
504 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
505 XGUI_Workshop* aWorkshop = aConnector->workshop();
506 ModuleBase_ISelection* aSel = workshop()->selection();
507 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
508 // if there are no selected objects in the viewer, that means that the selection in another
509 // place cased this method. It is necessary to return the false value to understande in above
510 // method that delete is not processed
511 if (aSelectedObj.count() == 0)
514 // avoid delete of the objects, which are not belong to the current sketch
515 // in order to do not delete results of other sketches
516 QObjectPtrList aSketchObjects;
517 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
518 for ( ; anIt != aLast; anIt++) {
519 ObjectPtr anObject = *anIt;
520 if (mySketchMgr->isObjectOfSketch(anObject))
521 aSketchObjects.append(anObject);
523 // if the selection contains only local selected presentations from other sketches,
524 // the Delete operation should not be done at all
525 if (aSketchObjects.size() == 0)
528 // the active nested sketch operation should be aborted unconditionally
530 anOperation->abort();
532 // 3. start operation
533 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
534 aMgr->startOperation(aDescription.toStdString());
536 // 4. delete features
537 // sketch feature should be skipped, only sub-features can be removed
538 // when sketch operation is active
539 std::set<FeaturePtr> anIgnoredFeatures;
540 anIgnoredFeatures.insert(mySketchMgr->activeSketch());
541 aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures);
544 aWorkshop->displayer()->updateViewer();
545 aMgr->finishOperation();
547 // Delete part with help of PartSet plugin
548 // TODO: the deleted objects has to be processed by multiselection
549 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
550 if (aObjects.size() == 1) {
551 ObjectPtr aObj = aObjects.first();
552 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
553 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
554 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
555 aMgr->startOperation(PartSetPlugin_Remove::ID());
556 FeaturePtr aFeature = aDoc->addFeature(PartSetPlugin_Remove::ID());
558 aMgr->finishOperation();
566 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
568 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
569 if (!anAIS.IsNull()) {
570 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
571 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
572 if (!aDim.IsNull()) {
573 aCtx->SetZLayer(aDim, myVisualLayerId);
575 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
577 aCtx->SetZLayer(aCons, myVisualLayerId);
582 void PartSet_Module::onViewTransformed(int theTrsfType)
584 // Set length of arrows constant in pixel size
585 // if the operation is panning or rotate or panglobal then do nothing
586 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
589 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
590 //Handle(V3d_View) aView = aViewer->activeView();
592 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
593 XGUI_Workshop* aWorkshop = aConnector->workshop();
594 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
595 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
597 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
598 Handle(V3d_View) aView;
600 for (aV3dViewer->InitDefinedViews();
601 aV3dViewer->MoreDefinedViews();
602 aV3dViewer->NextDefinedViews()) {
603 Handle(V3d_View) aV = aV3dViewer->DefinedView();
604 double aS = aV->Scale();
612 double aLen = aView->Convert(20);
614 SketcherPrs_Tools::setArrowSize(aLen);
615 bool isModified = false;
616 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
617 foreach (AISObjectPtr aAIS, aPrsList) {
618 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
620 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
621 if (!aDim.IsNull()) {
622 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
623 aContext->Redisplay(aDim, false);
628 aDisplayer->updateViewer();
631 ModuleBase_IDocumentDataModel* PartSet_Module::dataModel() const
637 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
639 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
640 int aSelected = aObjects.size();
641 if (aSelected == 1) {
642 bool hasResult = false;
643 bool hasFeature = false;
644 bool hasParameter = false;
645 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter);
647 SessionPtr aMgr = ModelAPI_Session::get();
648 ObjectPtr aObject = aObjects.first();
650 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
652 if (aMgr->activeDocument() == aPart->partDoc())
653 theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
655 theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
656 } else if (aObject->document() == aMgr->activeDocument()) {
657 if (hasParameter || hasFeature)
658 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
660 } else { // If feature is 0 the it means that selected root object (document)
661 if (aMgr->activeDocument() != aMgr->moduleDocument())
662 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
667 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
669 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
670 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
671 XGUI_Workshop* aWorkshop = aConnector->workshop();
672 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
673 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
674 QPalette aPalet = aLabel->palette();
676 SessionPtr aMgr = ModelAPI_Session::get();
677 DocumentPtr aActiveDoc = aMgr->activeDocument();
678 DocumentPtr aDoc = aMgr->moduleDocument();
679 QModelIndex aOldIndex = myDataModel->activePartIndex();
680 if (aActiveDoc == aDoc) {
681 if (aOldIndex.isValid())
682 aTreeView->setExpanded(aOldIndex, false);
683 myDataModel->deactivatePart();
684 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
686 std::string aGrpName = ModelAPI_ResultPart::group();
687 for (int i = 0; i < aDoc->size(aGrpName); i++) {
688 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
689 if (aPart->partDoc() == aActiveDoc) {
690 QModelIndex aIndex = myDataModel->partIndex(aPart);
691 if ((aOldIndex != aIndex) && aOldIndex.isValid()) {
692 aTreeView->setExpanded(aOldIndex, false);
694 if (myDataModel->activatePart(aIndex)) {
695 aTreeView->setExpanded(aIndex.parent(), true);
696 aTreeView->setExpanded(aIndex, true);
697 aPalet.setColor(QPalette::Text, Qt::black);
703 aLabel->setPalette(aPalet);