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_WidgetConstraintShapeSelector.h>
11 #include <PartSet_WidgetEditor.h>
12 #include <PartSet_SketcherMgr.h>
14 #include <ModuleBase_Operation.h>
15 #include <ModuleBase_IViewer.h>
16 #include <ModuleBase_IViewWindow.h>
17 #include <ModuleBase_IPropertyPanel.h>
18 #include <ModuleBase_WidgetEditor.h>
19 #include <ModuleBase_FilterFactory.h>
20 #include <ModuleBase_FilterLinearEdge.h>
21 #include <ModuleBase_FilterFace.h>
22 #include <ModuleBase_FilterMulti.h>
23 #include <ModuleBase_FilterCustom.h>
24 #include <ModuleBase_FilterNoConsructionSubShapes.h>
25 #include <GeomValidators_Edge.h>
26 #include <GeomValidators_EdgeOrVertex.h>
27 #include <GeomValidators_Face.h>
28 #include <GeomValidators_ConstructionComposite.h>
30 #include <PartSet_FilterSketchEntity.h>
32 #include <ModelAPI_Object.h>
33 #include <ModelAPI_Events.h>
34 #include <ModelAPI_Validator.h>
35 #include <ModelAPI_Data.h>
36 #include <ModelAPI_Session.h>
37 #include <ModelAPI_ShapeValidator.h>
39 #include <GeomDataAPI_Point2D.h>
40 #include <GeomDataAPI_Point.h>
41 #include <GeomDataAPI_Dir.h>
43 #include <XGUI_Displayer.h>
44 #include <XGUI_Workshop.h>
45 #include <XGUI_OperationMgr.h>
46 #include <XGUI_PropertyPanel.h>
47 #include <XGUI_ModuleConnector.h>
48 #include <XGUI_ContextMenuMgr.h>
49 #include <XGUI_Tools.h>
51 #include <SketchPlugin_Feature.h>
52 #include <SketchPlugin_Sketch.h>
53 #include <SketchPlugin_Line.h>
54 //#include <SketchPlugin_Arc.h>
55 //#include <SketchPlugin_Circle.h>
56 #include <SketchPlugin_ConstraintLength.h>
57 #include <SketchPlugin_ConstraintDistance.h>
58 #include <SketchPlugin_ConstraintParallel.h>
59 #include <SketchPlugin_ConstraintPerpendicular.h>
60 #include <SketchPlugin_ConstraintRadius.h>
62 #include <SketcherPrs_SymbolPrs.h>
63 #include <SketcherPrs_Tools.h>
65 #include <Events_Loop.h>
66 #include <Config_PropManager.h>
67 #include <Config_Keywords.h>
69 #include <StdSelect_TypeOfFace.hxx>
70 #include <TopoDS_Vertex.hxx>
72 #include <TopoDS_Shape.hxx>
73 #include <BRep_Tool.hxx>
74 #include <AIS_Dimension.hxx>
77 #include <QMouseEvent>
80 #include <QApplication>
81 #include <QMessageBox>
82 #include <QMainWindow>
84 #include <GeomAlgoAPI_FaceBuilder.h>
85 #include <GeomDataAPI_Dir.h>
91 /*!Create and return new instance of XGUI_Module*/
92 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
94 return new PartSet_Module(theWshop);
97 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
98 : ModuleBase_IModule(theWshop),
99 myRestartingMode(RM_None), myVisualLayerId(0)
101 mySketchMgr = new PartSet_SketcherMgr(this);
103 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
104 XGUI_Workshop* aWorkshop = aConnector->workshop();
106 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
107 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
108 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
109 this, SLOT(onOperationActivatedByPreselection()));
111 ModuleBase_IViewer* aViewer = theWshop->viewer();
112 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
113 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
114 connect(aViewer, SIGNAL(viewTransformed(int)),
115 SLOT(onViewTransformed(int)));
120 PartSet_Module::~PartSet_Module()
122 if (!myDocumentShapeFilter.IsNull())
123 myDocumentShapeFilter.Nullify();
126 void PartSet_Module::registerValidators()
128 //Registering of validators
129 SessionPtr aMgr = ModelAPI_Session::get();
130 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
131 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
132 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
133 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
134 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
135 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
136 aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
137 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
138 aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
140 aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge);
141 aFactory->registerValidator("GeomValidators_EdgeOrVertex",
142 new GeomValidators_EdgeOrVertex);
143 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
145 aFactory->registerValidator("GeomValidators_ConstructionComposite",
146 new GeomValidators_ConstructionComposite);
148 aFactory->registerValidator("PartSet_SketchEntityValidator",
149 new PartSet_SketchEntityValidator);
151 aFactory->registerValidator("PartSet_SameTypeAttr",
152 new PartSet_SameTypeAttrValidator);
155 void PartSet_Module::registerFilters()
157 //Registering of selection filters
158 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
159 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
161 //aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
162 //aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
163 //aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
164 //Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
165 //aFactory->registerFilter("NoConstructionSubShapesFilter",
166 // new ModuleBase_FilterCustom(aSelectFilter));
167 //Handle(SelectMgr_Filter) aSelectFilter = new PartSet_FilterSketchEntity(workshop());
168 //aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
171 void PartSet_Module::registerProperties()
173 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
175 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
176 Config_Prop::Integer, SKETCH_WIDTH);
179 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
181 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
182 mySketchMgr->commitNestedSketch(theOperation);
185 if (theOperation->isEditOperation())
187 // the selection is cleared after commit the create operation
188 // in order to do not use the same selected objects in the restarted operation
189 // for common behaviour, the selection is cleared even if the operation is not restarted
190 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
191 if (!aContext.IsNull())
192 aContext->ClearSelected();
194 /// Restart sketcher operations automatically
195 FeaturePtr aFeature = theOperation->feature();
196 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
197 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
198 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
199 myRestartingMode == RM_EmptyFeatureUsed)) {
200 myLastOperationId = theOperation->id();
201 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
203 launchOperation(myLastOperationId);
205 breakOperationSequence();
208 void PartSet_Module::breakOperationSequence()
210 myLastOperationId = "";
211 myLastFeature = FeaturePtr();
212 myRestartingMode = RM_None;
215 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
217 breakOperationSequence();
220 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
222 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
223 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
224 aViewer->AddZLayer(myVisualLayerId);
225 mySketchMgr->startSketch(theOperation);
227 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
228 mySketchMgr->startNestedSketch(theOperation);
231 if (myDocumentShapeFilter.IsNull())
232 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
233 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
236 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
238 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
239 mySketchMgr->stopSketch(theOperation);
240 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
241 aViewer->RemoveZLayer(myVisualLayerId);
244 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
245 mySketchMgr->stopNestedSketch(theOperation);
247 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
250 ModuleBase_Operation* PartSet_Module::currentOperation() const
252 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
253 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
254 return anOpMgr->currentOperation();
257 bool PartSet_Module::canUndo() const
259 bool aCanUndo = false;
260 SessionPtr aMgr = ModelAPI_Session::get();
261 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
262 aCanUndo = !aMgr->isOperation();
263 if (!aCanUndo) // check the enable state additionally by sketch manager
264 aCanUndo = aMgr->canUndo();
269 bool PartSet_Module::canRedo() const
271 bool aCanRedo = false;
272 SessionPtr aMgr = ModelAPI_Session::get();
273 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
274 aCanRedo = !aMgr->isOperation();
275 if (!aCanRedo) // check the enable state additionally by sketch manager
276 aCanRedo = aMgr->canRedo();
281 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
283 // the sketch manager put the restriction to the objects display
284 return mySketchMgr->canDisplayObject(theObject);
287 bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
289 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
290 if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
291 !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
294 ModuleBase_ISelection* aSelection = myWorkshop->selection();
295 QObjectPtrList aObjects = aSelection->selectedPresentations();
296 if (aObjects.size() > 0) {
297 bool hasFeature = false;
298 foreach(ObjectPtr aObject, aObjects)
300 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
301 if (aFeature.get() != NULL) {
306 theMenu->addAction(theStdActions["DELETE_CMD"]);
310 if (mySketchMgr->canSetAuxiliary(isAuxiliary)) {
311 QAction* anAction = action("AUXILIARY_CMD");
312 theMenu->addAction(anAction);
313 anAction->setChecked(isAuxiliary);
318 bool PartSet_Module::isMouseOverWindow()
320 return mySketchMgr->isMouseOverWindow();
323 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
325 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
326 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
327 // we have to manually activate the sketch label in edit mode
328 aPanel->activateWidget(aPanel->modelWidgets().first());
332 // Restart last operation type
333 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
334 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
335 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
336 // Initialise new line with first point equal to end of previous
337 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
339 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
340 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
341 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
343 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
344 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
345 aWgt->attributeID(), aPoint->x(), aPoint->y());
346 aPanel->activateNextWidget(aPnt2dWgt);
351 // Start editing constraint
352 if (theOperation->isEditOperation()) {
353 // TODO: #391 - to be removed
354 std::string aId = theOperation->id().toStdString();
355 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
356 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
357 // Find and activate widget for management of point for dimension line position
358 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
359 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
360 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
362 aPanel->activateWidget(aPntWgt);
372 void PartSet_Module::onSelectionChanged()
374 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
378 bool isSketcherOp = false;
379 // An edit operation is enable only if the current opeation is the sketch operation
380 if (mySketchMgr->activeSketch()) {
381 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
382 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
385 // Editing of constraints can be done on selection
386 ModuleBase_ISelection* aSelect = myWorkshop->selection();
387 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
388 if (aSelected.size() == 1) {
389 ModuleBase_ViewerPrs aPrs = aSelected.first();
390 ObjectPtr aObject = aPrs.object();
391 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
393 std::string aId = aFeature->getKind();
394 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
395 (aId == SketchPlugin_ConstraintLength::ID()) ||
396 (aId == SketchPlugin_ConstraintDistance::ID())) {
397 editFeature(aFeature);
404 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
406 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
407 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
408 anOpMgr->onKeyReleased(theEvent);
411 void PartSet_Module::onEnterReleased()
413 myRestartingMode = RM_EmptyFeatureUsed;
416 void PartSet_Module::onOperationActivatedByPreselection()
418 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
419 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
420 // Set final definitions if they are necessary
421 //propertyPanelDefined(aOperation);
423 /// Commit sketcher operations automatically
424 anOperation->commit();
428 void PartSet_Module::onNoMoreWidgets()
430 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
432 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
433 if (myRestartingMode != RM_Forbided)
434 myRestartingMode = RM_LastFeatureUsed;
435 anOperation->commit();
440 void PartSet_Module::onVertexSelected()
442 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
443 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
444 /// If last line finished on vertex the lines creation sequence has to be break
445 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
446 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
447 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
448 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
449 bool aFoundWidget = false;
450 bool aFoundObligatory = false;
451 for (; anIt != aLast && !aFoundObligatory; anIt++) {
453 aFoundWidget = *anIt == anActiveWidget;
455 aFoundObligatory = (*anIt)->isObligatory();
457 if (!aFoundObligatory)
458 myRestartingMode = RM_Forbided;
462 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
463 Config_WidgetAPI* theWidgetApi, std::string theParentId)
465 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
466 XGUI_Workshop* aWorkshop = aConnector->workshop();
467 ModuleBase_ModelWidget* aWgt = NULL;
468 if (theType == "sketch-start-label") {
469 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent,
470 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
471 aLabelWgt->setWorkshop(aWorkshop);
472 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
473 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
474 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
475 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
477 } else if (theType == "sketch-2dpoint_selector") {
478 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
479 aPointWgt->setWorkshop(aWorkshop);
480 aPointWgt->setSketch(mySketchMgr->activeSketch());
481 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
483 } if (theType == "point2ddistance") {
484 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
485 aDistanceWgt->setWorkshop(aWorkshop);
486 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
488 } if (theType == "sketch_shape_selector") {
489 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
490 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
491 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
492 aWgt = aShapeSelectorWgt;
493 } if (theType == "sketch_constraint_shape_selector") {
494 PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
495 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
496 aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
497 aWgt = aConstraintShapeSelectorWgt;
498 } if (theType == WDG_DOUBLEVALUE_EDITOR) {
499 aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
504 void PartSet_Module::createActions()
508 anAction = new QAction(tr("Auxiliary"), this);
509 anAction->setCheckable(true);
510 addAction("AUXILIARY_CMD", anAction);
513 QAction* PartSet_Module::action(const QString& theId) const
515 if (myActions.contains(theId))
516 return myActions[theId];
520 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
522 if (myActions.contains(theId))
523 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
524 theAction->setData(theId);
525 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
526 myActions[theId] = theAction;
529 void PartSet_Module::onAction(bool isChecked)
531 QAction* aAction = static_cast<QAction*>(sender());
532 QString anId = aAction->data().toString();
534 if (anId == "AUXILIARY_CMD") {
535 mySketchMgr->setAuxiliary(isChecked);
539 bool PartSet_Module::deleteObjects()
541 // 1. check whether the delete should be processed in the module
542 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
543 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
544 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
545 if (!isSketchOp && !isNestedOp)
548 // 2. find selected presentations
549 // selected objects should be collected before the current operation abort because
550 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
551 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
552 XGUI_Workshop* aWorkshop = aConnector->workshop();
553 ModuleBase_ISelection* aSel = aConnector->selection();
554 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
555 // if there are no selected objects in the viewer, that means that the selection in another
556 // place cased this method. It is necessary to return the false value to understande in above
557 // method that delete is not processed
558 if (aSelectedObj.count() == 0)
561 // the active nested sketch operation should be aborted unconditionally
563 anOperation->abort();
565 // 3. start operation
566 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
567 SessionPtr aMgr = ModelAPI_Session::get();
568 aMgr->startOperation(aDescription.toStdString());
570 // 4. delete features
571 // sketch feature should be skipped, only sub-features can be removed
572 // when sketch operation is active
573 std::set<FeaturePtr> anIgnoredFeatures;
574 anIgnoredFeatures.insert(mySketchMgr->activeSketch());
575 aWorkshop->deleteFeatures(aSelectedObj, anIgnoredFeatures);
578 aWorkshop->displayer()->updateViewer();
579 aMgr->finishOperation();
585 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
587 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
588 if (!anAIS.IsNull()) {
589 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
590 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
591 if (!aDim.IsNull()) {
592 aCtx->SetZLayer(aDim, myVisualLayerId);
594 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
596 aCtx->SetZLayer(aCons, myVisualLayerId);
601 void PartSet_Module::onViewTransformed(int theTrsfType)
603 // Set length of arrows constant in pixel size
604 // if the operation is panning or rotate or panglobal then do nothing
605 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
608 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
609 Handle(V3d_View) aView = aViewer->activeView();
611 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
612 XGUI_Workshop* aWorkshop = aConnector->workshop();
613 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
614 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
616 double aLen = aView->Convert(15);
618 SketcherPrs_Tools::setArrowSize(aLen);
619 bool isModified = false;
620 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
621 foreach (AISObjectPtr aAIS, aPrsList) {
622 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
624 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
625 if (!aDim.IsNull()) {
626 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
627 aContext->Redisplay(aDim, false);
632 aDisplayer->updateViewer();