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>
31 #include <GeomValidators_ZeroOffset.h>
34 #include <ModelAPI_Object.h>
35 #include <ModelAPI_Events.h>
36 #include <ModelAPI_Validator.h>
37 #include <ModelAPI_Data.h>
38 #include <ModelAPI_Session.h>
39 #include <ModelAPI_ShapeValidator.h>
41 #include <GeomDataAPI_Point2D.h>
42 #include <GeomDataAPI_Point.h>
43 #include <GeomDataAPI_Dir.h>
45 #include <XGUI_Displayer.h>
46 #include <XGUI_Workshop.h>
47 #include <XGUI_OperationMgr.h>
48 #include <XGUI_PropertyPanel.h>
49 #include <XGUI_ModuleConnector.h>
50 #include <XGUI_ContextMenuMgr.h>
51 #include <XGUI_Tools.h>
52 #include <XGUI_ObjectsBrowser.h>
54 #include <SketchPlugin_Feature.h>
55 #include <SketchPlugin_Sketch.h>
56 #include <SketchPlugin_Line.h>
57 #include <SketchPlugin_Arc.h>
58 #include <SketchPlugin_Circle.h>
59 #include <SketchPlugin_Point.h>
60 #include <SketchPlugin_ConstraintLength.h>
61 #include <SketchPlugin_ConstraintDistance.h>
62 #include <SketchPlugin_ConstraintParallel.h>
63 #include <SketchPlugin_ConstraintPerpendicular.h>
64 #include <SketchPlugin_ConstraintRadius.h>
66 #include <SketcherPrs_SymbolPrs.h>
67 #include <SketcherPrs_Tools.h>
69 #include <Events_Loop.h>
70 #include <Config_PropManager.h>
71 #include <Config_Keywords.h>
73 #include <StdSelect_TypeOfFace.hxx>
74 #include <TopoDS_Vertex.hxx>
76 #include <TopoDS_Shape.hxx>
77 #include <BRep_Tool.hxx>
78 #include <AIS_Dimension.hxx>
81 #include <QMouseEvent>
84 #include <QApplication>
85 #include <QMessageBox>
86 #include <QMainWindow>
89 #include <GeomAlgoAPI_FaceBuilder.h>
90 #include <GeomDataAPI_Dir.h>
98 /*!Create and return new instance of XGUI_Module*/
99 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
101 return new PartSet_Module(theWshop);
104 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
105 : ModuleBase_IModule(theWshop),
106 myRestartingMode(RM_None), myVisualLayerId(0)
108 mySketchMgr = new PartSet_SketcherMgr(this);
109 myDataModel = new PartSet_DocumentDataModel(this);
111 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
112 XGUI_Workshop* aWorkshop = aConnector->workshop();
114 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
115 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
116 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
117 this, SLOT(onOperationActivatedByPreselection()));
119 ModuleBase_IViewer* aViewer = theWshop->viewer();
120 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
121 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
122 connect(aViewer, SIGNAL(viewTransformed(int)),
123 SLOT(onViewTransformed(int)));
125 myMenuMgr = new PartSet_MenuMgr(this);
127 Events_Loop* aLoop = Events_Loop::loop();
128 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
131 PartSet_Module::~PartSet_Module()
133 if (!myDocumentShapeFilter.IsNull())
134 myDocumentShapeFilter.Nullify();
137 void PartSet_Module::registerValidators()
139 //Registering of validators
140 SessionPtr aMgr = ModelAPI_Session::get();
141 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
142 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
143 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
144 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
145 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
146 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
147 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
148 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
149 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
150 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
151 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
153 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
154 aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
156 aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
157 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
159 aFactory->registerValidator("GeomValidators_ConstructionComposite",
160 new GeomValidators_ConstructionComposite);
162 aFactory->registerValidator("GeomValidators_ZeroOffset",
163 new GeomValidators_ZeroOffset);
165 aFactory->registerValidator("PartSet_SketchEntityValidator",
166 new PartSet_SketchEntityValidator);
168 aFactory->registerValidator("PartSet_SameTypeAttr",
169 new PartSet_SameTypeAttrValidator);
172 void PartSet_Module::registerFilters()
174 //Registering of selection filters
175 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
176 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
179 void PartSet_Module::registerProperties()
181 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
183 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
184 Config_Prop::Integer, SKETCH_WIDTH);
187 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
189 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
190 mySketchMgr->commitNestedSketch(theOperation);
193 if (theOperation->isEditOperation())
195 // the selection is cleared after commit the create operation
196 // in order to do not use the same selected objects in the restarted operation
197 // for common behaviour, the selection is cleared even if the operation is not restarted
198 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
199 if (!aContext.IsNull())
200 aContext->ClearSelected();
202 /// Restart sketcher operations automatically
203 FeaturePtr aFeature = theOperation->feature();
204 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
205 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
206 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
207 myRestartingMode == RM_EmptyFeatureUsed)) {
208 myLastOperationId = theOperation->id();
209 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
211 launchOperation(myLastOperationId);
213 breakOperationSequence();
216 void PartSet_Module::breakOperationSequence()
218 myLastOperationId = "";
219 myLastFeature = FeaturePtr();
220 myRestartingMode = RM_None;
223 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
225 breakOperationSequence();
228 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
230 // Install the document filter before any other filter
231 if (myDocumentShapeFilter.IsNull())
232 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
233 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
235 ModuleBase_IModule::sendOperation(theOperation);
238 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
240 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
241 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
242 aViewer->AddZLayer(myVisualLayerId);
243 mySketchMgr->startSketch(theOperation);
245 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
246 mySketchMgr->startNestedSketch(theOperation);
250 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
252 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
253 mySketchMgr->stopSketch(theOperation);
254 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
255 aViewer->RemoveZLayer(myVisualLayerId);
258 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
259 mySketchMgr->stopNestedSketch(theOperation);
261 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
264 ModuleBase_Operation* PartSet_Module::currentOperation() const
266 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
267 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
268 return anOpMgr->currentOperation();
271 bool PartSet_Module::canUndo() const
273 bool aCanUndo = false;
274 SessionPtr aMgr = ModelAPI_Session::get();
275 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
276 aCanUndo = !aMgr->isOperation();
277 if (!aCanUndo) // check the enable state additionally by sketch manager
278 aCanUndo = aMgr->canUndo();
283 bool PartSet_Module::canRedo() const
285 bool aCanRedo = false;
286 SessionPtr aMgr = ModelAPI_Session::get();
287 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
288 aCanRedo = !aMgr->isOperation();
289 if (!aCanRedo) // check the enable state additionally by sketch manager
290 aCanRedo = aMgr->canRedo();
295 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
297 // the sketch manager put the restriction to the objects display
298 return mySketchMgr->canDisplayObject(theObject);
302 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
304 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
307 void PartSet_Module::activeSelectionModes(QIntList& theModes)
310 if (mySketchMgr->activeSketch().get())
311 PartSet_SketcherMgr::sketchSelectionModes(theModes);
314 bool PartSet_Module::isMouseOverWindow()
316 return mySketchMgr->isMouseOverWindow();
319 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
321 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
322 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
323 // we have to manually activate the sketch label in edit mode
324 aPanel->activateWidget(aPanel->modelWidgets().first());
328 // Restart last operation type
329 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
330 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
331 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
332 // Initialise new line with first point equal to end of previous
333 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
335 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
336 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
337 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
339 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
340 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
341 aWgt->attributeID(), aPoint->x(), aPoint->y());
342 aPanel->activateNextWidget(aPnt2dWgt);
347 // Start editing constraint
348 if (theOperation->isEditOperation()) {
349 // TODO: #391 - to be removed
350 std::string aId = theOperation->id().toStdString();
351 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
352 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
353 // Find and activate widget for management of point for dimension line position
354 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
355 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
356 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
358 aPanel->activateWidget(aPntWgt);
368 void PartSet_Module::onSelectionChanged()
370 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
374 bool isSketcherOp = false;
375 // An edit operation is enable only if the current opeation is the sketch operation
376 if (mySketchMgr->activeSketch()) {
377 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
378 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
381 // Editing of constraints can be done on selection
382 ModuleBase_ISelection* aSelect = myWorkshop->selection();
383 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
384 if (aSelected.size() == 1) {
385 ModuleBase_ViewerPrs aPrs = aSelected.first();
386 ObjectPtr aObject = aPrs.object();
387 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
389 std::string aId = aFeature->getKind();
390 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
391 (aId == SketchPlugin_ConstraintLength::ID()) ||
392 (aId == SketchPlugin_ConstraintDistance::ID())) {
393 editFeature(aFeature);
400 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
402 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
403 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
404 anOpMgr->onKeyReleased(theEvent);
407 void PartSet_Module::onEnterReleased()
409 myRestartingMode = RM_EmptyFeatureUsed;
412 void PartSet_Module::onOperationActivatedByPreselection()
414 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
415 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
416 // Set final definitions if they are necessary
417 //propertyPanelDefined(aOperation);
419 /// Commit sketcher operations automatically
420 anOperation->commit();
424 void PartSet_Module::onNoMoreWidgets()
426 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
428 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
429 if (myRestartingMode != RM_Forbided)
430 myRestartingMode = RM_LastFeatureUsed;
431 anOperation->commit();
436 void PartSet_Module::onVertexSelected()
438 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
439 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
440 /// If last line finished on vertex the lines creation sequence has to be break
441 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
442 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
443 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
444 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
445 bool aFoundWidget = false;
446 bool aFoundObligatory = false;
447 for (; anIt != aLast && !aFoundObligatory; anIt++) {
449 aFoundWidget = *anIt == anActiveWidget;
451 aFoundObligatory = (*anIt)->isObligatory();
453 if (!aFoundObligatory)
454 myRestartingMode = RM_Forbided;
458 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
459 Config_WidgetAPI* theWidgetApi, std::string theParentId)
461 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
462 XGUI_Workshop* aWorkshop = aConnector->workshop();
463 ModuleBase_ModelWidget* aWgt = NULL;
464 if (theType == "sketch-start-label") {
465 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent,
466 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
467 aLabelWgt->setWorkshop(aWorkshop);
468 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
469 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
470 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
471 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
473 } else if (theType == "sketch-2dpoint_selector") {
474 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
475 aPointWgt->setWorkshop(aWorkshop);
476 aPointWgt->setSketch(mySketchMgr->activeSketch());
477 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
479 } else if (theType == "point2ddistance") {
480 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
481 aDistanceWgt->setWorkshop(aWorkshop);
482 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
484 } else if(theType == "point2dangle") {
485 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent, theWidgetApi, theParentId);
486 anAngleWgt->setWorkshop(aWorkshop);
487 anAngleWgt->setSketch(mySketchMgr->activeSketch());
489 } else if (theType == "sketch_shape_selector") {
490 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
491 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
492 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
493 aWgt = aShapeSelectorWgt;
494 } else if (theType == "sketch_multi_selector") {
495 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
496 new PartSet_WidgetMultiSelector(theParent, workshop(), theWidgetApi, theParentId);
497 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
498 aWgt = aShapeSelectorWgt;
499 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
500 aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
501 } else if (theType == "export_file_selector") {
502 aWgt = new PartSet_WidgetFileSelector(theParent, workshop(), theWidgetApi, theParentId);
508 bool PartSet_Module::deleteObjects()
510 SessionPtr aMgr = ModelAPI_Session::get();
511 // 1. check whether the delete should be processed in the module
512 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
513 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
514 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
515 if (isSketchOp || isNestedOp) {
516 // 2. find selected presentations
517 // selected objects should be collected before the current operation abort because
518 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
519 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
520 XGUI_Workshop* aWorkshop = aConnector->workshop();
521 ModuleBase_ISelection* aSel = workshop()->selection();
522 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
523 // if there are no selected objects in the viewer, that means that the selection in another
524 // place cased this method. It is necessary to return the false value to understande in above
525 // method that delete is not processed
526 if (aSelectedObj.count() == 0)
529 // avoid delete of the objects, which are not belong to the current sketch
530 // in order to do not delete results of other sketches
531 QObjectPtrList aSketchObjects;
532 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
533 for ( ; anIt != aLast; anIt++) {
534 ObjectPtr anObject = *anIt;
535 if (mySketchMgr->isObjectOfSketch(anObject)) {
536 // sketch feature should be used in this list because workshop deletes features only
537 // results are skipped
538 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
539 aSketchObjects.append(aSketchFeature);
542 // if the selection contains only local selected presentations from other sketches,
543 // the Delete operation should not be done at all
544 if (aSketchObjects.size() == 0)
547 // the active nested sketch operation should be aborted unconditionally
549 anOperation->abort();
551 // 3. start operation
552 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
553 aMgr->startOperation(aDescription.toStdString());
555 // 4. delete features
556 // sketch feature should be skipped, only sub-features can be removed
557 // when sketch operation is active
558 std::set<FeaturePtr> anIgnoredFeatures;
559 anIgnoredFeatures.insert(mySketchMgr->activeSketch());
560 aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures);
563 aWorkshop->displayer()->updateViewer();
564 aMgr->finishOperation();
566 bool isPartRemoved = false;
567 // Delete part with help of PartSet plugin
568 // TODO: the deleted objects has to be processed by multiselection
569 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
570 if (aObjects.size() == 1) {
571 ObjectPtr aObj = aObjects.first();
572 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
573 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
574 // Remove feature should be created in the document of the part results
575 ResultPtr aPartResult = aFeature->firstResult();
576 if (aPartResult.get()) {
577 std::shared_ptr<ModelAPI_ResultPart> aPart =
578 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
579 DocumentPtr aPartDoc = aPart->partDoc();
580 if (aPartDoc.get()) {
581 aMgr->startOperation(PartSetPlugin_Remove::ID());
582 FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
584 aMgr->finishOperation();
585 isPartRemoved = true;
590 return isPartRemoved;
596 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
598 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
599 if (!anAIS.IsNull()) {
600 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
601 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
602 if (!aDim.IsNull()) {
603 aCtx->SetZLayer(aDim, myVisualLayerId);
605 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
607 aCtx->SetZLayer(aCons, myVisualLayerId);
612 void PartSet_Module::onViewTransformed(int theTrsfType)
614 // Set length of arrows constant in pixel size
615 // if the operation is panning or rotate or panglobal then do nothing
616 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
619 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
620 //Handle(V3d_View) aView = aViewer->activeView();
622 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
623 XGUI_Workshop* aWorkshop = aConnector->workshop();
624 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
625 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
627 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
628 Handle(V3d_View) aView;
630 for (aV3dViewer->InitDefinedViews();
631 aV3dViewer->MoreDefinedViews();
632 aV3dViewer->NextDefinedViews()) {
633 Handle(V3d_View) aV = aV3dViewer->DefinedView();
634 double aS = aV->Scale();
642 double aLen = aView->Convert(20);
644 SketcherPrs_Tools::setArrowSize(aLen);
645 bool isModified = false;
646 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
647 foreach (AISObjectPtr aAIS, aPrsList) {
648 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
650 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
651 if (!aDim.IsNull()) {
652 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
653 aContext->Redisplay(aDim, false);
658 aDisplayer->updateViewer();
662 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
664 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
666 QLineEdit* aLabel = aOB->activeDocLabel();
667 QPalette aPalet = aLabel->palette();
668 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
669 aLabel->setPalette(aPalet);
670 aOB->treeView()->setExpandsOnDoubleClick(false);
671 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
672 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
673 connect(aOB, SIGNAL(headerMouseDblClicked(const QModelIndex&)),
674 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
675 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
676 myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&)));
681 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
683 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
684 int aSelected = aObjects.size();
685 SessionPtr aMgr = ModelAPI_Session::get();
686 if (aSelected == 1) {
687 bool hasResult = false;
688 bool hasFeature = false;
689 bool hasParameter = false;
690 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter);
692 ObjectPtr aObject = aObjects.first();
694 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
695 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
696 bool isPart = aPart.get() ||
697 (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
699 DocumentPtr aPartDoc;
701 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
703 if (aPart.get()) // this may be null is Part feature is disabled
704 aPartDoc = aPart->partDoc();
705 if (aMgr->activeDocument() == aPartDoc)
706 theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
708 theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
709 } else if (aObject->document() == aMgr->activeDocument()) {
710 if (hasParameter || hasFeature)
711 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
713 } else { // If feature is 0 the it means that selected root object (document)
714 if (aMgr->activeDocument() != aMgr->moduleDocument())
715 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
717 } else if (aSelected == 0) {
718 // if there is no selection then it means that upper label is selected
719 QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
720 if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
721 if (aMgr->activeDocument() != aMgr->moduleDocument())
722 theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
726 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
728 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
729 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
730 XGUI_Workshop* aWorkshop = aConnector->workshop();
731 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
732 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
733 QPalette aPalet = aLabel->palette();
735 SessionPtr aMgr = ModelAPI_Session::get();
736 DocumentPtr aActiveDoc = aMgr->activeDocument();
737 DocumentPtr aDoc = aMgr->moduleDocument();
738 QModelIndex aOldIndex = myDataModel->activePartTree();
739 if (aActiveDoc == aDoc) {
740 if (aOldIndex.isValid())
741 aTreeView->setExpanded(aOldIndex, false);
742 myDataModel->deactivatePart();
743 aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
745 std::string aGrpName = ModelAPI_ResultPart::group();
746 for (int i = 0; i < aDoc->size(aGrpName); i++) {
747 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
748 if (aPart->partDoc() == aActiveDoc) {
749 QModelIndex aIndex = myDataModel->partIndex(aPart);
750 if (myDataModel->activatePart(aIndex)) {
751 if (aOldIndex.isValid())
752 aTreeView->setExpanded(aOldIndex, false);
753 aTreeView->setExpanded(myDataModel->activePartTree(), true);
754 aPalet.setColor(QPalette::Text, Qt::black);
760 aLabel->setPalette(aPalet);
761 aWorkshop->updateCommandStatus();
763 // Update displayed objects in order to update active color
764 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
765 QObjectPtrList aObjects = aDisplayer->displayedObjects();
766 foreach(ObjectPtr aObj, aObjects)
767 aDisplayer->redisplay(aObj, false);
768 aDisplayer->updateViewer();
772 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
774 SessionPtr aMgr = ModelAPI_Session::get();
775 if (!theIndex.isValid()) {
776 aMgr->setActiveDocument(aMgr->moduleDocument());
779 if (theIndex.column() != 0) // Use only first column
781 ObjectPtr aObj = myDataModel->object(theIndex);
782 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
783 if (!aPart.get()) { // Probably this is Feature
784 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
785 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
786 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
789 if (aPart.get()) { // if this is a part
790 if (aPart->partDoc() == aMgr->activeDocument()) {
791 aMgr->setActiveDocument(aMgr->moduleDocument());