1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "PartSet_SketcherMgr.h"
22 #include "PartSet_Filters.h"
23 #include "PartSet_SketcherReentrantMgr.h"
24 #include "PartSet_Module.h"
25 #include "PartSet_MouseProcessor.h"
26 #include "PartSet_Tools.h"
27 #include "PartSet_WidgetSketchLabel.h"
28 #include "PartSet_WidgetEditor.h"
29 #include "PartSet_ResultSketchPrs.h"
30 #include "PartSet_ExternalPointsMgr.h"
31 #include "PartSet_PreviewSketchPlane.h"
33 #include <XGUI_ModuleConnector.h>
34 #include <XGUI_Displayer.h>
35 #include <XGUI_Workshop.h>
36 #include <XGUI_ContextMenuMgr.h>
37 #include <XGUI_Selection.h>
38 #include <XGUI_SelectionActivate.h>
39 #include <XGUI_SelectionMgr.h>
40 #include <XGUI_ModuleConnector.h>
41 #include <XGUI_PropertyPanel.h>
42 #include <XGUI_ViewerProxy.h>
43 #include <XGUI_OperationMgr.h>
44 #include <XGUI_ErrorMgr.h>
45 #include <XGUI_Tools.h>
47 #include <ModuleBase_IPropertyPanel.h>
48 #include <ModuleBase_ISelection.h>
49 #include <ModuleBase_IViewer.h>
50 #include <ModuleBase_IWorkshop.h>
51 #include <ModuleBase_IViewWindow.h>
52 #include <ModuleBase_ModelWidget.h>
53 #include <ModuleBase_Operation.h>
54 #include <ModuleBase_OperationFeature.h>
55 #include <ModuleBase_Operation.h>
56 #include <ModuleBase_WidgetEditor.h>
57 #include <ModuleBase_ViewerPrs.h>
58 #include <ModuleBase_Tools.h>
59 #include <ModuleBase_ResultPrs.h>
60 #include <ModuleBase_ViewerFilters.h>
62 #include <GeomDataAPI_Point2D.h>
64 #include <GeomAPI_Shape.h>
66 #include <Events_Loop.h>
68 #include <SketchPlugin_Line.h>
69 #include <SketchPlugin_Sketch.h>
70 #include <SketchPlugin_Point.h>
71 #include <SketchPlugin_Arc.h>
72 #include <SketchPlugin_Circle.h>
73 #include <SketchPlugin_Ellipse.h>
74 #include <SketchPlugin_EllipticArc.h>
75 #include <SketchPlugin_ConstraintLength.h>
76 #include <SketchPlugin_ConstraintDistance.h>
77 #include <SketchPlugin_ConstraintParallel.h>
78 #include <SketchPlugin_ConstraintPerpendicular.h>
79 #include <SketchPlugin_ConstraintRadius.h>
80 #include <SketchPlugin_ConstraintRigid.h>
81 #include <SketchPlugin_ConstraintHorizontal.h>
82 #include <SketchPlugin_ConstraintVertical.h>
83 #include <SketchPlugin_ConstraintEqual.h>
84 #include <SketchPlugin_ConstraintTangent.h>
85 #include <SketchPlugin_ConstraintCoincidence.h>
86 #include <SketchPlugin_Fillet.h>
87 #include <SketchPlugin_ConstraintMirror.h>
88 #include <SketchPlugin_ConstraintAngle.h>
89 #include <SketchPlugin_ConstraintCollinear.h>
90 #include <SketchPlugin_ConstraintMiddle.h>
91 #include <SketchPlugin_MultiRotation.h>
92 #include <SketchPlugin_MultiTranslation.h>
93 #include <SketchPlugin_IntersectionPoint.h>
94 #include <SketchPlugin_Projection.h>
95 #include <SketchPlugin_ConstraintDistanceAlongDir.h>
96 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
97 #include <SketchPlugin_ConstraintDistanceVertical.h>
99 #include <SketcherPrs_Tools.h>
101 #include <SelectMgr_IndexedMapOfOwner.hxx>
102 #include <StdSelect_BRepOwner.hxx>
104 //#include <AIS_DimensionSelectionMode.hxx>
105 #include <AIS_Shape.hxx>
106 #include <AIS_Dimension.hxx>
108 #include <ModelAPI_Events.h>
109 #include <ModelAPI_Session.h>
110 #include <ModelAPI_AttributeString.h>
112 #include <ModelAPI_Validator.h>
113 #include <ModelAPI_Tools.h>
115 #include <QMouseEvent>
116 #include <QApplication>
118 #include <QMessageBox>
119 #include <QMainWindow>
123 //#define DEBUG_DO_NOT_BY_ENTER
124 //#define DEBUG_SKETCHER_ENTITIES
125 //#define DEBUG_SKETCH_ENTITIES_ON_MOVE
126 //#define DRAGGING_DEBUG
127 //#define DEBUG_CURSOR
130 #ifdef DRAGGING_DEBUG
134 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
135 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge,
136 /// put the function result as is to the list of results.
137 /// \param theOwner a viewer selected owner
138 /// \param theFeature a feature, where the attribute is searched
139 /// \param theSketch a current sketch
140 /// \param theSelectedAttribute an output list of attributes
141 /// \param theSelectedResults an output list of edge results
142 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
143 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
144 const ResultPtr& theResult,
145 std::set<AttributePtr>& theSelectedAttributes,
146 std::set<ResultPtr>& theSelectedResults,
147 TopTools_MapOfShape& theShapes)
149 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
150 if (aBRepOwner.IsNull())
152 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
153 aBRepOwner->Selectable());
154 if (aBRepOwner->HasShape()) {
155 const TopoDS_Shape& aShape = aBRepOwner->Shape();
156 theShapes.Add(aShape);
157 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
158 if (aShapeType == TopAbs_VERTEX) {
159 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
161 if (aPntAttr.get() != NULL)
162 theSelectedAttributes.insert(aPntAttr);
164 else if (aShapeType == TopAbs_EDGE &&
165 theSelectedResults.find(theResult) == theSelectedResults.end()) {
166 theSelectedResults.insert(theResult);
171 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
172 : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false),
173 myDragDone(false), myIsMouseOverWindow(false),
174 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
175 myIsPopupMenuActive(false), myExternalPointsMgr(0), myNoDragMoving(false)
177 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
178 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
180 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
182 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
183 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
185 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
186 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
188 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
189 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
191 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
192 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
194 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
195 XGUI_Workshop* aWorkshop = aConnector->workshop();
196 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
198 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
199 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
200 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
202 mySketchPlane = new PartSet_PreviewSketchPlane();
204 registerSelectionFilter(SF_SketchCirclePointFilter, new PartSet_CirclePointFilter(anIWorkshop));
205 registerSelectionFilter(SF_SketchPlaneFilter, new ModuleBase_ShapeInPlaneFilter());
207 Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_DOF_OBJECTS));
210 PartSet_SketcherMgr::~PartSet_SketcherMgr()
212 delete mySketchPlane;
215 void PartSet_SketcherMgr::onEnterViewPort()
217 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
218 // created feature because it should be done in onMouseMove(). Some widgets watch
219 // the mouse move and use the cursor position to update own values. If the presentaion is
220 // redisplayed before this update, the feature presentation jumps from reset value to current.
221 myIsMouseOverWindow = true;
223 #ifdef DEBUG_DO_NOT_BY_ENTER
227 // It is switched off because of
228 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
229 if (canChangeCursor(getCurrentOperation())) {
230 QCursor* aCurrentCursor = QApplication::overrideCursor();
231 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
232 QApplication::setOverrideCursor(PartSet_Tools::getOperationCursor());
233 //#ifdef DEBUG_CURSOR
234 // qDebug("onEnterViewPort() : Qt::CrossCursor");
239 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
242 operationMgr()->onValidateOperation();
244 // we need change displayed state of the current operation feature
245 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
246 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
247 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
248 // presentation becomes valid and redisplay happens
249 //ModuleBase_Operation* aOperation = getCurrentOperation();
250 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
251 (getCurrentOperation());
253 FeaturePtr aFeature = aFOperation->feature();
254 if (aFeature.get() && aFeature->data()->isValid()) {
255 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
260 void PartSet_SketcherMgr::onLeaveViewPort()
262 myIsMouseOverViewProcessed = false;
263 myIsMouseOverWindow = false;
265 #ifdef DEBUG_DO_NOT_BY_ENTER
269 if (canChangeCursor(getCurrentOperation())) {
270 QApplication::restoreOverrideCursor();
271 //#ifdef DEBUG_CURSOR
272 // qDebug("onLeaveViewPort() : None");
276 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
279 // the method should be performed if the popup menu is called,
280 // the reset of the current widget should not happen
281 if (myIsPopupMenuActive)
284 // it is important to validate operation here only if sketch entity create operation is active
285 // because at this operation we reacts to the mouse leave/enter view port
286 operationMgr()->onValidateOperation();
288 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
289 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
290 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
291 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
292 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
293 // obtained after reset value
294 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
295 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
297 anActiveWidget->reset();
299 // hides the presentation of the current operation feature
300 // the feature is to be erased here, but it is correct to call canDisplayObject because
301 // there can be additional check (e.g. editor widget in distance constraint)
302 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
303 (getCurrentOperation());
305 FeaturePtr aFeature = aFOperation->feature();
306 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
308 // we should update viewer after the presentation are hidden in the viewer
309 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
310 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
314 //Temporary commented as we do not modify values in property panel
315 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
317 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
318 myModule->sketchReentranceMgr()->isInternalEditActive())
320 // it is necessary to save current selection in order to restore it after the values are modifed
321 storeSelection(ST_SelectAndHighlightType);
323 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
324 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
325 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
326 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
329 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
331 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
332 myModule->sketchReentranceMgr()->isInternalEditActive()) {
333 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
336 // it is necessary to restore current selection in order to restore it after values are modified
338 myCurrentSelection.clear();
340 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
341 // viewer happens by deselect/select the modified objects. The flag should be restored after
342 // the selection processing. The update viewer should be also called.
343 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
344 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
345 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
346 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
347 aDisplayer->updateViewer();
351 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
353 // Clear dragging mode
354 myIsDragging = false;
356 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
358 //get2dPoint(theWnd, theEvent, myClickedPoint);
359 if (!(theEvent->buttons() & Qt::LeftButton))
362 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
363 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
364 //if (!aViewer->canDragByMouse())
367 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
368 (getCurrentOperation());
372 bool isEditing = aFOperation->isEditOperation();
373 bool aCanDrag = aViewer->canDragByMouse();
375 //if (!aViewer->canDragByMouse() && isEditing) {
376 // // Do not edit by dragging
381 // If the current widget is a selector, do nothing, it processes the mouse press
382 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
383 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
388 // Use only for sketch operations
389 if (myCurrentSketch) {
390 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
393 bool isSketcher = isSketchOperation(aFOperation);
394 bool isSketchOpe = isNestedSketchOperation(aFOperation);
396 // Avoid non-sketch operations
397 if ((!isSketchOpe) && (!isSketcher))
400 // Ignore creation sketch operation
401 if ((!isSketcher) && (!isEditing))
404 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
405 storeSelection(aHasShift ? ST_SelectAndHighlightType : ST_HighlightType, myCurrentSelection);
407 if (myCurrentSelection.empty()) {
408 if (isSketchOpe && (!isSketcher))
409 // commit previous operation
410 if (!aFOperation->commit())
411 aFOperation->abort();
414 // Init flyout point for radius rotation
415 FeaturePtr aFeature = myCurrentSelection.begin().key();
416 get2dPoint(theWnd, theEvent, myCurrentPoint);
422 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
424 if (aFeature.get() != NULL) {
425 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
426 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
427 if (aSPFeature.get() &&
428 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
429 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
430 DataPtr aData = aSPFeature->data();
431 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
432 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
433 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
434 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
437 } else if (isSketchOpe && isEditing) {
438 // If selected another object commit current result
439 bool aPrevLaunchingState = myIsEditLaunching;
440 /// store editing state for Edit operation in order to do not clear highlight by restart
441 /// of edit operation.
442 /// Internal edit should not be stored as editing operation as the result will be a
443 /// creation operation, where previous selection should not be used(and will be cleared)
444 myIsEditLaunching = !myModule->sketchReentranceMgr()->isInternalEditActive();
446 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
447 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFOperation->feature());
448 bool isRelaunchEditing = true;
449 if (aSPFeature->isExternal()) {
450 foreach(FeaturePtr aF, myCurrentSelection.keys()) {
451 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aF,
452 aSPFeature->getKind());
453 if (aProducerFeature == aSPFeature) {
454 isRelaunchEditing = false;
460 if (myCurrentSelection.size() > 1)
461 isRelaunchEditing = !myCurrentSelection.contains(aSPFeature);
463 if (isRelaunchEditing)
464 aFOperation->commit();
470 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
471 if (isRelaunchEditing)
473 myIsEditLaunching = aPrevLaunchingState;
474 if (aFeature.get() != NULL) {
475 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
476 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
477 if (aSPFeature.get() &&
478 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
479 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
480 DataPtr aData = aSPFeature->data();
481 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
482 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
483 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
484 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
491 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
493 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
494 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
496 aViewer->enableDrawMode(myPreviousDrawModeEnabled);
498 bool aWasDragging = myIsDragging;
499 myIsDragging = false;
501 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent)) {
504 // if mouse is pressed when it was over view and at release the mouse is out of view, do nothing
505 if (!myIsMouseOverViewProcessed) {
508 //if (!aViewer->canDragByMouse())
510 ModuleBase_OperationFeature* aOp =
511 dynamic_cast<ModuleBase_OperationFeature*>(getCurrentOperation());
513 bool aStartNoDragOperation = !aViewer->canDragByMouse() && aOp->isEditOperation();
514 if (aStartNoDragOperation || myNoDragMoving) {
515 // Process edit operation without dragging
516 if (myCurrentSelection.size() > 0)
517 myNoDragMoving = !myNoDragMoving;
519 myNoDragMoving = false;
523 restoreSelection(myCurrentSelection);
524 myCurrentSelection.clear();
528 if (isNestedSketchOperation(aOp)) {
529 // Only for sketcher operations
532 /// the previous selection is lost by mouse release in the viewer(Select method), but
533 /// it is still stored in myCurrentSelection. So, it is possible to restore selection
534 /// It is important for drag(edit with mouse) of sketch entities.
535 restoreSelection(myCurrentSelection);
536 myCurrentSelection.clear();
544 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
545 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
547 aProcessor->mouseReleased(theWnd, theEvent);
550 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
552 #ifdef DEBUG_SKETCH_ENTITIES_ON_MOVE
553 CompositeFeaturePtr aSketch = activeSketch();
555 std::cout << "mouse move SKETCH FEATURES [" << aSketch->numberOfSubs() << "]:" << std::endl;
557 for (int i = 0, aNbSubs = aSketch->numberOfSubs(); i < aNbSubs; i++) {
558 //std::cout << getFeatureInfo(aSketch->subFeature(i), false) << std::endl;
559 anInfo.append(ModuleBase_Tools::objectInfo(aSketch->subFeature(i)));
561 QString anInfoStr = anInfo.join("\n");
562 qDebug(QString("%1").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
565 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
568 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
569 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
570 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
572 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
573 #ifdef DRAGGING_DEBUG
577 // 1. perform the widget mouse move functionality and display the presentation
578 // the mouse move should be processed in the widget, if it can in order to visualize correct
579 // presentation. These widgets correct the feature attribute according to the mouse position
580 ModuleBase_ModelWidget* anActiveWidget = myModule->activeWidget();
581 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
583 aProcessor->mouseMoved(theWnd, theEvent);
584 if (!myIsMouseOverViewProcessed) {
585 myIsMouseOverViewProcessed = true;
587 // the feature is to be erased here, but it is correct to call canDisplayObject because
588 // there can be additional check (e.g. editor widget in distance constraint)
589 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
590 (getCurrentOperation());
592 FeaturePtr aFeature = aFOperation->feature();
593 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
596 aDisplayer->updateViewer();
597 #ifdef DRAGGING_DEBUG
598 cout << "Mouse move processing " << t.elapsed() << endl;
601 //myClickedPoint.clear();
603 if (myIsDragging || myNoDragMoving) {
604 // 1. the current selection is saved in the mouse press method in order to restore it after
606 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
607 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
608 // deselected). This flag should be restored in the slot, processed the mouse release signal.
609 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
610 if (!aCurrentOperation)
612 if (isSketchOperation(aCurrentOperation))
613 return; // No edit operation activated
615 #ifdef DRAGGING_DEBUG
620 Handle(V3d_View) aView = theWnd->v3dView();
621 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
623 get2dPoint(theWnd, theEvent, aMousePnt);
625 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
626 new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
627 std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
628 new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
630 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
631 // viewer happens by deselect/select the modified objects. The flag should be restored after
632 // the selection processing. The update viewer should be also called.
633 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
635 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
636 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
637 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
638 aLast = myCurrentSelection.end();
639 // 4. the features and attributes modification(move)
640 bool isModified = false;
641 for (; anIt != aLast; anIt++) {
642 FeaturePtr aFeature = anIt.key();
644 std::set<AttributePtr> anAttributes = anIt.value().myAttributes;
645 // Process selection by attribute: the priority to the attribute
646 if (!anAttributes.empty()) {
647 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
648 anAttLast = anAttributes.end();
649 for (; anAttIt != anAttLast; anAttIt++) {
650 AttributePtr anAttr = *anAttIt;
651 if (anAttr.get() == NULL)
653 std::string aAttrId = anAttr->id();
654 DataPtr aData = aFeature->data();
655 if (aData->isValid()) {
656 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
657 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
658 if (aPoint.get() != NULL) {
659 bool isImmutable = aPoint->setImmutable(true);
661 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
662 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
663 aMessage->setMovedAttribute(aPoint);
664 aMessage->setOriginalPosition(anOriginalPosition);
665 aMessage->setCurrentPosition(aCurrentPosition);
666 Events_Loop::loop()->send(aMessage);
669 aPoint->setImmutable(isImmutable);
675 // Process selection by feature
676 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
677 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
678 if (aSketchFeature) {
679 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
680 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
681 aMessage->setMovedObject(aFeature);
682 aMessage->setOriginalPosition(anOriginalPosition);
683 aMessage->setCurrentPosition(aCurrentPosition);
684 Events_Loop::loop()->send(aMessage);
689 // the modified state of the current operation should be updated if there are features, which
692 aCurrentOperation->onValuesChanged();
693 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
695 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
697 // 5. it is necessary to save current selection in order to restore it after the features moving
698 restoreSelection(myCurrentSelection);
699 // 6. restore the update viewer flag and call this update
700 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
701 aDisplayer->updateViewer();
703 #ifdef DRAGGING_DEBUG
704 cout << "Mouse move processing " << t.elapsed() << endl;
708 myCurrentPoint = aMousePnt;
712 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
714 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
715 (getCurrentOperation());
716 if (aFOperation && aFOperation->isEditOperation()) {
717 std::string aId = aFOperation->id().toStdString();
718 if (isDistanceOperation(aFOperation))
720 // Activate dimension value editing on double click
721 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
722 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
723 // Find corresponded widget to activate value editing
724 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
725 std::string anId = aWgt->attributeID();
726 if (anId == SketchPlugin_Constraint::VALUE() ||
727 anId == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() ||
728 anId == SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()) {
729 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
731 anEditor->showPopupEditor();
739 void PartSet_SketcherMgr::onApplicationStarted()
741 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
742 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
743 XGUI_Workshop* aWorkshop = aConnector->workshop();
744 PartSet_SketcherReentrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
746 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
747 if (aPropertyPanel) {
748 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
749 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
751 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
752 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
753 //connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
754 // aReentranceMgr, SLOT(onWidgetActivated()));
757 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
758 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
759 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
761 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
762 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
763 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
766 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
768 //if (!myClickedPoint.myIsInitialized)
771 //ModuleBase_Operation* aOperation = getCurrentOperation();
772 // the distance constraint feature should not use the clickedd point
773 // this is workaround in order to don't throw down the flyout point value,
774 // set by execute() method of these type of features
775 //if (isDistanceOperation(aOperation))
778 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
780 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
784 void PartSet_SketcherMgr::onBeforeContextMenu()
786 myIsPopupMenuActive = true;
789 void PartSet_SketcherMgr::onAfterContextMenu()
791 myIsPopupMenuActive = false;
794 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
797 Handle(V3d_View) aView = theWnd->v3dView();
798 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
800 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
801 thePoint.setValue(aX, anY);
804 void PartSet_SketcherMgr::launchEditing()
806 if (!myCurrentSelection.empty()) {
807 FeaturePtr aFeature = myCurrentSelection.begin().key();
808 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
809 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
811 if (!aSPFeature->isExternal())
812 myModule->editFeature(aSPFeature);
814 // need to edit a feature (Projection/IntersectionPoint),
815 // which produces current External feature
816 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
817 SketchPlugin_Projection::ID());
818 if (!aProducerFeature.get())
819 aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
820 SketchPlugin_IntersectionPoint::ID());
821 if (aProducerFeature.get())
822 myModule->editFeature(aProducerFeature);
828 bool PartSet_SketcherMgr::sketchSolverError()
830 bool anError = false;
831 CompositeFeaturePtr aSketch = activeSketch();
833 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
834 anError = !aAttributeString->value().empty();
839 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
842 if (!theFeature.get() || !theFeature->data()->isValid())
845 CompositeFeaturePtr aSketch = activeSketch();
846 if (aSketch.get() && aSketch == theFeature) {
847 std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
848 anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
853 void PartSet_SketcherMgr::clearClickedFlags()
855 //myClickedPoint.clear();
856 myCurrentPoint.clear();
859 const QStringList& PartSet_SketcherMgr::replicationsIdList()
861 static QStringList aReplicationIds;
862 if (aReplicationIds.size() == 0) {
863 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
864 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
865 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
867 return aReplicationIds;
870 const QStringList& PartSet_SketcherMgr::constraintsIdList()
872 static QStringList aConstraintIds;
873 if (aConstraintIds.size() == 0) {
874 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
875 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
876 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
877 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
878 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
879 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
880 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
881 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
882 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
883 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
884 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
885 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
886 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
887 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
888 aConstraintIds << SketchPlugin_ConstraintMirror::ID().c_str();
889 aConstraintIds << SketchPlugin_MultiTranslation::ID().c_str();
890 aConstraintIds << SketchPlugin_MultiRotation::ID().c_str();
891 aConstraintIds << SketchPlugin_ConstraintDistanceAlongDir::ID().c_str();
892 aConstraintIds << SketchPlugin_ConstraintDistanceHorizontal::ID().c_str();
893 aConstraintIds << SketchPlugin_ConstraintDistanceVertical::ID().c_str();
895 return aConstraintIds;
898 void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSketch,
901 if (!theSketch.get() || !PartSet_Tools::sketchPlane(theSketch).get())
904 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
905 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
906 theModes.append(SketcherPrs_Tools::Sel_Constraint);
907 theModes.append(TopAbs_VERTEX);
908 theModes.append(TopAbs_EDGE);
911 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ObjectPtr& theObj)
913 Handle(AIS_InteractiveObject) aPrs;
915 FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
916 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
917 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
919 aPrs = new PartSet_ResultSketchPrs(aResult);
924 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
926 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
929 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
931 bool aNestedSketch = false;
933 FeaturePtr anActiveSketch = activeSketch();
934 if (anActiveSketch.get() && theOperation) {
935 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
936 anActiveSketch->getKind().c_str());
937 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
939 if (aSketchOperation && aFOperation) {
940 FeaturePtr aFeature = aFOperation->feature();
941 if (aFeature.get()) {
942 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
943 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
947 return aNestedSketch;
950 bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const
952 bool aNestedSketch = false;
954 FeaturePtr anActiveSketch = activeSketch();
955 if (anActiveSketch.get()) {
956 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
957 anActiveSketch->getKind().c_str());
958 if (aSketchOperation) {
959 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
960 aNestedSketch = aGrantedOpIds.contains(theFeatureKind);
963 return aNestedSketch;
966 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
967 const CompositeFeaturePtr& theSketch) const
969 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
971 return aFOperation && !aFOperation->isEditOperation() &&
972 isNestedSketchOperation(aFOperation);
975 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
976 const CompositeFeaturePtr& theSketch) const
978 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
980 return aFOperation && aFOperation->isEditOperation() &&
981 isNestedSketchOperation(aFOperation);
984 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
986 return (theId == SketchPlugin_Line::ID()) ||
987 (theId == SketchPlugin_Point::ID()) ||
988 (theId == SketchPlugin_Arc::ID()) ||
989 (theId == SketchPlugin_Circle::ID()) ||
990 (theId == SketchPlugin_Ellipse::ID()) ||
991 (theId == SketchPlugin_Projection::ID()) ||
992 (theId == SketchPlugin_IntersectionPoint::ID()) ||
993 (theId == SketchPlugin_EllipticArc::ID());
996 bool PartSet_SketcherMgr::isExternalFeature(const FeaturePtr& theFeature)
998 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
999 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
1000 return aSPFeature.get() && aSPFeature->isExternal();
1003 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
1005 std::string anId = theOperation ? theOperation->id().toStdString() : "";
1007 return isDistanceKind(anId);
1010 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
1012 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
1013 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
1014 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
1015 (theKind == SketchPlugin_ConstraintAngle::ID()) ||
1016 (theKind == SketchPlugin_ConstraintDistanceHorizontal::ID()) ||
1017 (theKind == SketchPlugin_ConstraintDistanceVertical::ID()) ||
1018 (theKind == SketchPlugin_ConstraintDistanceAlongDir::ID());
1021 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
1023 static Events_ID EVENT_ATTR = Events_Loop::loop()->eventByName(EVENT_VISUAL_ATTRIBUTES);
1024 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1026 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1027 (getCurrentOperation());
1031 SketcherPrs_Tools::setPixelRatio(ModuleBase_Tools::currentPixelRatio());
1033 myModule->onViewTransformed();
1035 // Display all sketcher sub-Objects
1036 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
1037 double aSizeOfView = 0;
1038 std::shared_ptr<GeomAPI_Pnt> aCentralPoint;
1039 if (aFOperation->isEditOperation() &&
1040 mySketchPlane->getDefaultSizeOfView(myCurrentSketch, aSizeOfView, aCentralPoint)) {
1041 mySketchPlane->setSizeOfView(aSizeOfView, true, aCentralPoint);
1044 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
1045 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1047 // Hide sketcher result
1048 std::list<ResultPtr> aResults = myCurrentSketch->results();
1049 std::list<ResultPtr>::const_iterator aIt;
1050 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1051 (*aIt)->setDisplayed(false);
1053 myCurrentSketch->setDisplayed(false);
1055 // Remove invalid sketch entities
1056 std::set<FeaturePtr> anInvalidFeatures;
1057 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
1058 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1059 for (int i = 0; i < aNumberOfSubs; i++) {
1060 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1061 if (aFeature.get()) {
1062 if (!aFactory->validate(aFeature))
1063 anInvalidFeatures.insert(aFeature);
1066 if (!anInvalidFeatures.empty()) {
1067 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1068 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
1070 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
1071 aLast = anInvalidFeatures.end();
1072 // separate features to references to parameter features and references to others
1073 QStringList anInvalidFeatureNames;
1074 for (; anIt != aLast; anIt++) {
1075 FeaturePtr aFeature = *anIt;
1077 anInvalidFeatureNames.append(aFeature->name().c_str());
1079 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
1080 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
1081 std::set<FeaturePtr> aFeatureRefsToDelete;
1082 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
1083 aFeatureRefsToDelete, aPrefixInfo)) {
1084 if (!aFeatureRefsToDelete.empty())
1085 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1086 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
1087 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1088 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
1089 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
1093 // update state of overconstraint listener should be done before sketch features/results
1094 // display (as the display will ask custom color from the listener)
1095 myModule->overconstraintListener()->setActive(true);
1096 // Display sketcher objects
1098 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1099 aNumberOfSubs = myCurrentSketch->numberOfSubs();
1100 for (int i = 0; i < aNumberOfSubs; i++) {
1101 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1102 #ifdef DEBUG_SKETCHER_ENTITIES
1103 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1105 std::list<ResultPtr> aResults = aFeature->results();
1106 std::list<ResultPtr>::const_iterator aIt;
1107 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1108 if ((*aIt)->isDisplayed())
1109 // Display object if it was created outside of GUI
1110 aECreator->sendUpdated((*aIt), EVENT_DISP);
1112 (*aIt)->setDisplayed(true);
1114 if (aFeature->isDisplayed())
1115 aECreator->sendUpdated(aFeature, EVENT_DISP);
1117 aFeature->setDisplayed(true);
1118 aECreator->sendUpdated(aFeature, EVENT_ATTR);
1120 #ifdef DEBUG_SKETCHER_ENTITIES
1121 QString anInfoStr = anInfo.join(";\t");
1122 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1125 bool aHasPlane = false;
1126 std::shared_ptr<GeomAPI_Pln> aPln;
1127 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1128 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1129 if (!aFilter.IsNull())
1130 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1132 workshop()->selectionActivate()->updateSelectionFilters();
1133 workshop()->selectionActivate()->updateSelectionModes();
1135 Events_Loop::loop()->flush(EVENT_DISP);
1136 Events_Loop::loop()->flush(EVENT_ATTR);
1138 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1140 workshop()->viewer()->set2dMode(true);
1142 PartSet_Fitter* aFitter = new PartSet_Fitter(this);
1143 myModule->workshop()->viewer()->setFitter(aFitter);
1146 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1148 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1149 PartSet_Fitter* aFitter = (PartSet_Fitter*)myModule->workshop()->viewer()->fitter();
1150 myModule->workshop()->viewer()->setFitter(0);
1153 myIsMouseOverWindow = false;
1154 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1155 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1156 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1158 if (myExternalPointsMgr) {
1159 delete myExternalPointsMgr;
1160 myExternalPointsMgr = 0;
1162 onShowPoints(false);
1164 DataPtr aData = myCurrentSketch->data();
1165 if (!aData->isValid()) {
1166 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1167 // The sketch was aborted
1168 myCurrentSketch = CompositeFeaturePtr();
1169 mySketchPlane->eraseSketchPlane(myModule->workshop());
1171 // Erase all sketcher objects
1172 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1173 foreach (ObjectPtr aObj, aObjects) {
1174 DataPtr aObjData = aObj->data();
1175 if (!aObjData->isValid())
1176 aObj->setDisplayed(false);
1180 // Hide all sketcher sub-Objects
1181 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1182 for (int i = 0; i < aNumberOfSubs; i++) {
1183 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1184 std::list<ResultPtr> aResults = aFeature->results();
1185 std::list<ResultPtr>::const_iterator aIt;
1186 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1187 (*aIt)->setDisplayed(false);
1189 aFeature->setDisplayed(false);
1191 // Display sketcher result
1192 std::list<ResultPtr> aResults = myCurrentSketch->results();
1193 std::list<ResultPtr>::const_iterator aIt;
1194 Events_Loop* aLoop = Events_Loop::loop();
1195 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1197 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1199 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1200 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1201 (*aIt)->setDisplayed(true);
1202 // this display event is needed because sketch already may have "displayed" state,
1203 // but not displayed while it is still active (issue 613, abort of existing sketch)
1204 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1207 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1208 myCurrentSketch->setDisplayed(true);
1210 myCurrentSketch = CompositeFeaturePtr();
1211 mySketchPlane->eraseSketchPlane(myModule->workshop());
1213 Events_Loop::loop()->flush(aDispEvent);
1215 workshop()->selectionActivate()->updateSelectionFilters();
1216 workshop()->selectionActivate()->updateSelectionModes();
1217 workshop()->viewer()->set2dMode(false);
1220 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1222 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1223 QCursor* aCurrentCursor = QApplication::overrideCursor();
1224 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1225 QApplication::setOverrideCursor(PartSet_Tools::getOperationCursor());
1226 //#ifdef DEBUG_CURSOR
1227 // qDebug("startNestedSketch() : Qt::CrossCursor");
1233 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1235 myIsMouseOverViewProcessed = true;
1236 operationMgr()->onValidateOperation();
1237 // when sketch nested operation is stopped the cursor should be restored unconditionally
1238 if (canChangeCursor(theOperation)) {
1239 QApplication::restoreOverrideCursor();
1241 qDebug("stopNestedSketch() : None");
1244 /// improvement to deselect automatically all eventual selected objects, when
1245 // returning to the neutral point of the Sketcher
1246 bool isClearSelectionPossible = true;
1247 if (myIsEditLaunching) {
1248 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1251 FeaturePtr aFeature = aFOperation->feature();
1252 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1253 isClearSelectionPossible = false;
1257 if (isClearSelectionPossible)
1258 workshop()->selector()->clearSelection();
1259 if (myPointsHighlight.size())
1263 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1265 if (isNestedCreateOperation(theOperation, activeSketch())) {
1266 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1269 FeaturePtr aFeature = aFOperation->feature();
1270 // it is necessary to check the the feature data validity because
1271 // some kind of features are removed by an operation commit(the macro state of a feature)
1272 if (aFeature.get() && aFeature->data()->isValid()) {
1273 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1279 bool PartSet_SketcherMgr::sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType)
1281 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1284 void PartSet_SketcherMgr::registerSelectionFilter(
1285 const ModuleBase_SelectionFilterType theFilterType, const Handle(SelectMgr_Filter)& theFilter)
1287 mySelectionFilterTypes.insert(theFilterType);
1288 myModule->registerSelectionFilter(theFilterType, theFilter);
1291 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1293 bool isOperationStopped = false;
1294 ModuleBase_Operation* anOperation = getCurrentOperation();
1295 if(anOperation && isNestedSketchOperation(anOperation)) {
1296 // Set final definitions if they are necessary
1297 //propertyPanelDefined(aOperation);
1298 /// Commit sketcher operations automatically
1299 /// distance operation are able to show popup editor to modify the distance value
1300 /// after entering the value, the operation should be committed/aborted(by Esc key)
1301 bool aCanCommitOperation = true;
1302 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1304 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1305 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1306 aCanCommitOperation);
1307 if (!aValueAccepted)
1308 return isOperationStopped;
1311 if (aCanCommitOperation)
1312 isOperationStopped = anOperation->commit();
1314 anOperation->abort();
1315 isOperationStopped = true;
1318 return isOperationStopped;
1321 bool PartSet_SketcherMgr::canUndo() const
1323 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1326 bool PartSet_SketcherMgr::canRedo() const
1328 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1331 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1333 bool aCanErase = true;
1334 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1335 if (myCurrentSketch.get()) {
1336 return !isObjectOfSketch(theObject);
1341 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1343 bool aCanDisplay = true;
1345 bool aHasActiveSketch = activeSketch().get() != NULL;
1346 if (aHasActiveSketch) {
1347 // 1. the sketch feature should not be displayed during the sketch active operation
1348 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1349 // nested features can be visualized
1350 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1351 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1352 aCanDisplay = false;
1354 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1355 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1356 /// some sketch entities should be never shown, e.g. projection feature
1357 if (aSketchFeature.get())
1358 aCanDisplay = aSketchFeature->canBeDisplayed();
1360 else { // there are no an active sketch
1361 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1362 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1363 if (aFeature.get() != NULL) {
1364 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1365 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1366 if (aSketchFeature.get()) {
1367 aCanDisplay = false;
1372 // 3. the method should not filter the objects, which are not related to the current operation.
1373 // The object is filtered just if it is a current operation feature or this feature result
1375 bool isObjectFound = false;
1376 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1377 (getCurrentOperation());
1379 FeaturePtr aFeature = aFOperation->feature();
1380 if (aFeature.get()) {
1381 std::list<ResultPtr> aResults = aFeature->results();
1382 if (theObject == aFeature)
1383 isObjectFound = true;
1385 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1386 for (; anIt != aLast && !isObjectFound; anIt++) {
1387 isObjectFound = *anIt == theObject;
1392 if (isObjectFound) {
1393 // 4. For created nested feature operation do not display the created feature if
1394 // the mouse curstor leaves the OCC window.
1395 // The correction cases, which ignores this condition:
1396 // a. the property panel values modification
1397 // b. the popup menu activated
1398 // c. widget editor control
1399 #ifndef DEBUG_DO_NOT_BY_ENTER
1400 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1401 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1402 ModuleBase_WidgetEditor* anEditorWdg =
1403 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1404 // the active widget editor should not influence here. The presentation should be visible
1405 // always when this widget is active.
1406 if (!anEditorWdg && !myIsPopupMenuActive) {
1407 // during a nested create operation, the feature is redisplayed only
1408 // if the mouse over view
1409 // of there was a value modified in the property panel after the mouse left the view
1410 aCanDisplay = canDisplayCurrentCreatedFeature();
1417 // checks the sketcher constraints visibility according to active sketch check box states
1419 bool aProcessed = false;
1420 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1421 if (aFeature.get()) {
1422 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1424 aCanDisplay = aConstraintDisplayed;
1431 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1432 const PartSet_Tools::ConstraintVisibleState& theState,
1433 bool& isProcessed) const
1435 bool aSwitchedOn = true;
1437 const QStringList& aConstrIds = constraintsIdList();
1439 std::string aKind = theFeature->getKind();
1440 if (aConstrIds.contains(QString(aKind.c_str()))) {
1441 bool isTypedConstraint = false;
1444 case PartSet_Tools::Dimensional: {
1445 bool isDistance = isDistanceKind(aKind);
1448 aSwitchedOn = myIsConstraintsShown[theState];
1452 case PartSet_Tools::Geometrical: {
1453 bool isGeometrical = !isDistanceKind(aKind);
1454 if (isGeometrical) {
1456 aSwitchedOn = myIsConstraintsShown[theState];
1460 case PartSet_Tools::Any: {
1462 bool isDistance = isDistanceKind(aKind);
1464 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1466 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1476 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1478 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1479 (getCurrentOperation());
1480 if (aFOperation && myCurrentSketch.get()) {
1481 // find results of the current operation
1482 // these results should not be proposed to be deleted
1483 FeaturePtr anOperationFeature = aFOperation->feature();
1484 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1485 std::set<ResultPtr> anOperationResults;
1486 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1487 aRLast = anOperationResultList.end();
1488 for (; aRIt != aRLast; aRIt++)
1489 anOperationResults.insert(*aRIt);
1491 std::set<FeaturePtr> anObjectsToBeDeleted;
1492 QStringList anObjectsToBeDeletedNames;
1493 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1494 for (; anIt != aLast; anIt++) {
1495 ObjectPtr anObject = *anIt;
1496 bool aCanErase = true;
1497 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1498 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1499 // the result is found between current feature results
1500 if (anOperationResults.find(aResult) != anOperationResults.end())
1503 if (aResult.get()) {
1504 // Display sketcher objects
1505 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1506 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1507 std::list<ResultPtr> aResults = aFeature->results();
1508 std::list<ResultPtr>::const_iterator anIt;
1509 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1510 aCanErase = *anIt != aResult;
1515 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1516 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1517 anObjectsToBeDeleted.insert(aFeature);
1518 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1522 if (!anObjectsToBeDeleted.empty()) {
1523 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1524 QString aMessage = tr("The following features have incorrect presentation and \
1525 will be hidden: %1. Would you like to delete them?")
1526 .arg(aFeatureNames);
1527 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1528 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1529 QMessageBox::Cancel);
1530 if (anAnswer == QMessageBox::Ok) {
1531 QObjectPtrList anObjects;
1532 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1533 aLast = anObjectsToBeDeleted.end();
1534 for (; anIt != aLast; anIt++)
1535 anObjects.append(*anIt);
1536 SessionPtr aMgr = ModelAPI_Session::get();
1537 DocumentPtr aDoc = aMgr->activeDocument();
1538 bool aIsOp = aMgr->isOperation();
1540 aMgr->startOperation();
1541 workshop()->deleteFeatures(anObjects);
1542 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1543 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1544 //Events_Loop::loop()->flush(aDeletedEvent);
1545 //Events_Loop::loop()->flush(aRedispEvent);
1548 aMgr->finishOperation();
1554 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1556 bool aCanDisplay = myIsMouseOverWindow;
1558 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1560 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1565 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1567 return isNestedCreateOperation(theOperation, activeSketch()) ||
1568 myModule->sketchReentranceMgr()->isInternalEditActive();
1571 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1573 return myIsConstraintsShown;
1576 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1578 if (!myCurrentSketch.get())
1580 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1581 if (anObjectFeature.get()) {
1582 int aSize = myCurrentSketch->numberOfSubs();
1583 FeaturePtr aCurrentFeature;
1584 for (int i = 0; i < aSize; i++) {
1585 aCurrentFeature = myCurrentSketch->subFeature(i);
1586 if (myCurrentSketch->subFeature(i) == anObjectFeature)
1593 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1595 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1596 if (!aFilter.IsNull())
1597 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1599 workshop()->selectionActivate()->updateSelectionModes();
1602 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1603 ModuleBase_IWorkshop* theWorkshop,
1604 bool& theCanCommitOperation)
1606 bool isValueAccepted = false;
1607 theCanCommitOperation = false;
1609 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1611 FeaturePtr aFeature = aFOperation->feature();
1612 // editor is shown only if all attribute references are filled by preseletion
1613 bool anAllRefAttrInitialized = true;
1615 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1616 ModelAPI_AttributeRefAttr::typeId());
1617 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1618 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1619 anAllRefAttrInitialized = (*anIt)->isInitialized();
1621 if (anAllRefAttrInitialized) {
1622 // Activate dimension value editing on double click
1623 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1624 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1625 // Find corresponded widget to activate value editing
1626 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1627 if (aWgt->attributeID() == "ConstraintValue") {
1628 // the featue should be displayed in order to find the AIS text position,
1629 // the place where the editor will be shown
1630 aFeature->setDisplayed(true);
1631 /// the execute is necessary to perform in the feature compute for flyout position
1632 aFeature->execute();
1634 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1635 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1637 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1639 int aX = 0, anY = 0;
1641 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1642 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1643 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1644 Handle(AIS_InteractiveObject) anAISIO;
1645 if (anAIS.get() != NULL) {
1646 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1648 if (anAIS.get() != NULL) {
1649 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1651 if (!anAISIO.IsNull()) {
1652 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1653 if (!aDim.IsNull()) {
1654 gp_Pnt aPosition = aDim->GetTextPosition();
1656 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1657 Handle(V3d_View) aView = aViewer->activeView();
1659 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1661 QWidget* aViewPort = aViewer->activeViewPort();
1662 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1667 anEditor->setCursorPosition(aX, anY);
1668 isValueAccepted = anEditor->showPopupEditor(false);
1669 theCanCommitOperation = true;
1675 return isValueAccepted;
1678 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1679 const FeaturePtr& theSketch,
1680 ModuleBase_IWorkshop* theWorkshop,
1681 const FeatureToSelectionMap& theSelection,
1682 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1684 if (theFeature.get() == NULL)
1687 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1688 SelectionInfo anInfo = anIt.value();
1689 std::set<AttributePtr> aSelectedAttributes = anInfo.myAttributes;
1690 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1692 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1694 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1695 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1697 // 1. found the feature's owners. Check the AIS objects of the constructions
1698 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1699 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1700 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1702 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1703 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1704 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1705 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1706 if (!anOwner.IsNull())
1707 theOwnersToSelect.Add(anOwner);
1711 // 2. found the feature results's owners
1712 std::list<ResultPtr> aResults = theFeature->results();
1713 std::list<ResultPtr>::const_iterator aIt;
1715 bool isSameShape = false;
1716 if (aResults.size() > 0) {
1717 ResultPtr aFirstResult = theFeature->firstResult();
1718 if (aFirstResult.get() && aFirstResult->shape().get()) {
1719 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1720 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1723 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1724 ResultPtr aResult = *aIt;
1725 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1726 if (aAISObj.get() == NULL)
1728 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1730 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1731 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1732 bool aFoundLocalShape = false;
1733 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1734 Handle(StdSelect_BRepOwner) anOwner =
1735 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1736 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1738 const TopoDS_Shape& aShape = anOwner->Shape();
1739 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1740 if (aShapeType == TopAbs_VERTEX) {
1741 AttributePtr aPntAttr =
1742 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1743 if (aPntAttr.get() != NULL &&
1744 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end())
1745 theOwnersToSelect.Add(anOwner);
1746 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1747 theOwnersToSelect.Add(anOwner);
1750 else if (aShapeType == TopAbs_EDGE) {
1751 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1752 // try to restore local selection on Shape result
1753 // we can do this only if the shape was not changed
1754 theOwnersToSelect.Add(anOwner);
1755 aFoundLocalShape = true;
1760 if (!aFoundLocalShape) {
1761 // result owners are put in the list of selection only if local selected shapes were not
1763 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1764 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1765 Handle(StdSelect_BRepOwner) anOwner =
1766 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1767 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1769 // select whole result
1770 theOwnersToSelect.Add(anOwner);
1777 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1778 const bool isToConnect)
1780 //Temporary commented as we do not modify values in property panel
1782 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1783 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1784 //connect(theWidget, SIGNAL(afterValuesChanged()),
1785 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1786 connect(theWidget, SIGNAL(afterValuesChanged()),
1787 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1790 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1791 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1792 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1793 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1794 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1795 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1799 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1801 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1802 (getCurrentOperation());
1804 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1805 isNestedSketchOperation(aFOperation) &&
1806 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1807 FeaturePtr aFeature = aFOperation->feature();
1808 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1813 //void PartSet_SketcherMgr::customisePresentation(const ObjectPtr& theObject)
1815 // ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1816 // (getCurrentOperation());
1817 // if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1818 // isNestedSketchOperation(aFOperation)))
1819 // SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1821 // // update entities selection priorities
1822 // FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1823 // if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1824 // // update priority for feature
1825 // updateSelectionPriority(aFeature, aFeature);
1826 // // update priority for results of the feature
1827 // std::list<ResultPtr> aResults = aFeature->results();
1828 // std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1829 // for (; anIt != aLastIt; anIt++)
1830 // updateSelectionPriority(*anIt, aFeature);
1834 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1836 return myModule->workshop()->currentOperation();
1839 //**************************************************************
1840 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1842 ModuleBase_ModelWidget* aWidget = 0;
1843 ModuleBase_Operation* anOperation = getCurrentOperation();
1845 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1847 aWidget = aPanel->activeWidget();
1852 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1853 const bool isEditOperation,
1854 const bool isToDisplay,
1855 const bool isFlushRedisplay)
1857 #ifdef DEBUG_DO_NOT_BY_ENTER
1861 if (isEditOperation || !theFeature.get())
1864 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1865 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1867 // 1. change visibility of the object itself, here the presentable object is processed,
1868 // e.g. constraints features
1869 //FeaturePtr aFeature = aFOperation->feature();
1870 std::list<ResultPtr> aResults = theFeature->results();
1872 theFeature->setDisplayed(true);
1874 theFeature->setDisplayed(false);
1876 // change visibility of the object results, e.g. non-constraint features
1877 std::list<ResultPtr>::const_iterator aIt;
1878 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1880 (*aIt)->setDisplayed(true);
1883 (*aIt)->setDisplayed(false);
1886 if (isFlushRedisplay)
1887 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1890 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1891 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1893 if (!myCurrentSketch.get())
1896 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1897 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1898 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1900 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1901 aStoredPrs = aSelect->getHighlighted();
1903 QList<FeaturePtr> aFeatureList;
1904 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1905 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1906 ModuleBase_ISelection::AllControls);
1907 aStoredPrs.append(aSelected);
1910 // 1. it is necessary to save current selection in order to restore it after the features moving
1911 theCurrentSelection.clear();
1913 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1914 aLast = aStoredPrs.end();
1916 CompositeFeaturePtr aSketch = activeSketch();
1917 for (; anIt != aLast; anIt++) {
1918 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1919 ObjectPtr anObject = aPrs->object();
1920 if (!anObject.get())
1923 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1924 FeaturePtr aFeature;
1926 aFeature = ModelAPI_Feature::feature(aResult);
1928 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1930 if (!aFeature.get())
1933 std::set<AttributePtr> aSelectedAttributes;
1934 std::set<ResultPtr> aSelectedResults;
1935 SelectionInfo anInfo;
1936 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1937 anInfo = theCurrentSelection.find(aFeature).value();
1939 TopoDS_Shape aFirstShape;
1940 ResultPtr aFirstResult = aFeature->firstResult();
1941 if (aFirstResult.get() && aFirstResult->shape().get())
1942 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1943 anInfo.myFirstResultShape = aFirstShape;
1944 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1945 if (aResult.get()) {
1946 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1947 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1950 std::list<ResultPtr> aResults = aFeature->results();
1951 std::list<ResultPtr>::const_iterator aIt;
1952 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1953 ResultPtr aResult = *aIt;
1954 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1955 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1958 theCurrentSelection[aFeature] = anInfo;
1960 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1963 void PartSet_SketcherMgr::restoreSelection(
1964 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1966 if (!myCurrentSketch.get())
1969 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1970 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1971 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1972 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
1973 aSLast = theCurrentSelection.end();
1974 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1975 anOwnersToSelect.Clear();
1976 for (; aSIt != aSLast; aSIt++) {
1977 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
1980 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1983 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1985 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1987 updateBySketchParameters(aType, theState);
1988 myModule->workshop()->viewer()->update();
1991 void PartSet_SketcherMgr::updateBySketchParameters(
1992 const PartSet_Tools::ConstraintVisibleState& theType,
1995 if (myCurrentSketch.get() == NULL)
1998 bool aPrevState = myIsConstraintsShown[theType];
1999 myIsConstraintsShown[theType] = theState;
2002 case PartSet_Tools::Geometrical:
2003 case PartSet_Tools::Dimensional: {
2004 if (aPrevState != theState) {
2005 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2006 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
2007 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
2008 for (int i = 0; i < aNumberOfSubs; i++) {
2009 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
2010 bool aProcessed = false;
2011 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
2013 aSubFeature->setDisplayed(aConstraintDisplayed);
2015 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2019 case PartSet_Tools::Expressions: {
2020 if (aPrevState != theState) {
2021 /// call all sketch features redisplay, the expression state will be corrected in customize
2022 /// of distance presentation
2023 SketcherPrs_Tools::ParameterStyle aStyle = myIsConstraintsShown[PartSet_Tools::Expressions]
2024 ? SketcherPrs_Tools::ParameterText : SketcherPrs_Tools::ParameterValue;
2025 SketcherPrs_Tools::setParameterStyle(aStyle);
2026 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2027 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
2034 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
2035 FeaturePtr theFeature)
2037 if (!theObject.get() || !theFeature.get())
2040 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
2041 Handle(AIS_InteractiveObject) anAISIO;
2042 if (anAIS.get() != NULL) {
2043 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
2046 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
2047 int anAdditionalPriority = 0;
2049 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2050 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
2051 if (aSPFeature.get() != NULL) {
2053 // 2. Simple segments
2054 // 3. External objects (violet color)
2055 // 4. Auxiliary segments (dotted)
2056 // StdSelect_BRepSelectionTool::Load uses priority calculating:
2057 // Standard_Integer aPriority =
2058 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
2059 // Priority of Vertex is 8, edge(segment) is 7.
2060 // It might be not corrected as provides the condition above.
2061 bool isExternal = aSPFeature->isExternal();
2062 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
2064 if (!isExternal && !isAuxiliary)
2065 anAdditionalPriority = 30;
2068 anAdditionalPriority = 20;
2069 // auxiliary feature
2071 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
2072 // edges/vertices of local selection on not-sketch objects
2074 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
2075 if (!aResult.IsNull()) {
2076 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
2082 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
2084 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
2085 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
2086 return aConnector->workshop();
2089 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
2091 return workshop()->operationMgr();
2094 void PartSet_SketcherMgr::onShowPoints(bool toShow)
2096 if (!myCurrentSketch.get())
2098 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2099 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
2100 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
2102 bool aToUpdate = false;
2104 std::list<ResultPtr> aFreePoints = SketcherPrs_Tools::getFreePoints(myCurrentSketch);
2106 // Delete obsolete presentations
2107 std::list<ResultPtr> aDelList;
2108 foreach(ResultPtr aObj, myPointsHighlight.keys()) {
2109 bool aFound = (std::find(aFreePoints.begin(), aFreePoints.end(), aObj) != aFreePoints.end());
2111 aDelList.push_back(aObj);
2113 foreach(ResultPtr aObj, aDelList) {
2114 aContext->Remove(myPointsHighlight[aObj], false);
2116 myPointsHighlight.remove(aObj);
2119 // Display new objects
2120 QList<ResultPtr> aKeysList = myPointsHighlight.keys();
2121 std::list<ResultPtr>::const_iterator aIt;
2122 for (aIt = aFreePoints.cbegin(); aIt != aFreePoints.cend(); aIt++) {
2123 if (!aKeysList.contains(*aIt)) {
2124 GeomShapePtr aShapePtr = (*aIt)->shape();
2125 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
2126 Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape);
2127 aShapePrs->SetColor(Quantity_NOC_BLUE1);
2128 aShapePrs->SetZLayer(Graphic3d_ZLayerId_Top);
2129 Handle(Prs3d_Drawer) aDrawer = aShapePrs->Attributes();
2130 if (aDrawer->HasOwnPointAspect()) {
2131 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
2132 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
2133 aDrawer->PointAspect()->SetScale(2);
2136 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2));
2137 aContext->Display(aShapePrs, false);
2138 aContext->Deactivate(aShapePrs);
2139 myPointsHighlight[*aIt] = aShapePrs;
2145 foreach(Handle(AIS_Shape) aPrs, myPointsHighlight.values()) {
2146 aContext->Remove(aPrs, false);
2149 myPointsHighlight.clear();
2155 void PartSet_SketcherMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
2157 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOF_OBJECTS)) {
2158 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
2159 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
2160 std::set<ObjectPtr> aObjects = anUpdateMsg->objects();
2161 std::set<ObjectPtr>::const_iterator aIt;
2162 QList<ModuleBase_ViewerPrsPtr> aPrsList;
2163 for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
2164 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aIt);
2165 if (aFeature.get()) {
2166 std::list<ResultPtr> aRes = aFeature->results();
2167 std::list<ResultPtr>::const_iterator aIt;
2168 for (aIt = aRes.cbegin(); aIt != aRes.cend(); ++aIt) {
2169 ModuleBase_ViewerPrsPtr aPrsPtr(new ModuleBase_ViewerPrs(*aIt));
2170 aPrsList.append(aPrsPtr);
2174 if (aPrsList.size() > 0) {
2175 myModule->workshop()->setSelected(aPrsList);
2180 bool isExternal(const ObjectPtr& theObject)
2182 AttributeSelectionPtr aAttr =
2183 theObject->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
2185 return aAttr->context().get() != NULL && !aAttr->isInvalid();
2189 bool isCopy(const ObjectPtr& theObject)
2191 AttributeBooleanPtr anAttr = theObject->data()->boolean(SketchPlugin_SketchEntity::COPY_ID());
2193 return anAttr->value();
2197 bool isIncludeToResult(const ObjectPtr& theObject)
2199 AttributeBooleanPtr anAttr;
2200 std::set<AttributePtr> aRefsToMe = theObject->data()->refsToMe();
2201 std::set<AttributePtr>::const_iterator aIt;
2202 for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) {
2203 if ((*aIt)->id() == SketchPlugin_Projection::PROJECTED_FEATURE_ID()) {
2204 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aIt)->owner());
2205 if (aFeature.get()) {
2206 anAttr = aFeature->data()->boolean(SketchPlugin_Projection::INCLUDE_INTO_RESULT());
2208 return anAttr->value();
2215 //**************************************************************************************
2216 std::vector<int> PartSet_SketcherMgr::colorOfObject(const ObjectPtr& theObject,
2217 const FeaturePtr& theFeature, bool isConstruction) const
2219 static const QStringList& aConstrIds = constraintsIdList();
2220 PartSet_OverconstraintListener* aOCListener = myModule->overconstraintListener();
2221 std::string aKind = theFeature->getKind();
2223 if (isDistanceKind(aKind)) {
2224 if (aOCListener->isConflictingObject(theObject))
2225 return Config_PropManager::color("Visualization", "sketch_overconstraint_color");
2226 return Config_PropManager::color("Visualization", "sketch_dimension_color");
2228 if (isExternal(theFeature))
2229 return Config_PropManager::color("Visualization", "sketch_external_color");
2231 return Config_PropManager::color("Visualization", "sketch_auxiliary_color");
2233 if (aOCListener->isFullyConstrained()) {
2234 return Config_PropManager::color("Visualization", "sketch_fully_constrained_color");
2236 else if (aOCListener->isConflictingObject(theObject)) {
2237 return Config_PropManager::color("Visualization", "sketch_overconstraint_color");
2239 return Config_PropManager::color("Visualization", "sketch_entity_color");
2242 //**************************************************************************************
2243 void PartSet_SketcherMgr::customizeSketchPresentation(const ObjectPtr& theObject,
2244 const AISObjectPtr& thePrs) const
2246 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
2248 // set color from preferences
2249 std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
2250 aFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
2251 bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
2253 std::vector<int> aColor = colorOfObject(theObject, aFeature, isConstruction);
2254 if (!aColor.empty()) {
2255 // The code below causes redisplay again
2256 if (ModelAPI_Session::get()->isOperation()) {
2257 AttributeIntArrayPtr aColorAttr = theObject->data()->intArray(ModelAPI_Result::COLOR_ID());
2258 if (aColorAttr.get()) {
2259 aColorAttr->setSize(3, false);
2260 // Set the color attribute in order do not use default colors in the presentation object
2261 for (int i = 0; i < 3; i++)
2262 aColorAttr->setValue(i, aColor[i], false);
2265 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
2268 int aShapeType = thePrs->getShapeType();
2269 // a compound is processed like the edge because the
2270 // arc feature uses the compound for presentable AIS
2271 if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
2274 if (isExternal(aFeature)) {
2275 thePrs->setWidth(1);
2278 std::string aKind = aFeature->getKind();
2279 if (isDistanceKind(aKind))
2282 if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
2283 if (isConstruction) {
2284 // Set axilliary line
2285 thePrs->setWidth(SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY());
2286 thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY());
2289 int aWidth = Config_PropManager::integer("Visualization", "sketch_line_width");
2290 thePrs->setWidth(aWidth);
2291 thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE());
2294 else if (aShapeType == 7) { // otherwise this is a vertex
2295 // The width value do not have effect on the point presentation.
2296 // It is defined in order to extend selection area of the object.
2297 thePrs->setWidth(17);
2298 // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
2300 if (isCopy(aFeature) && !isIncludeToResult(aFeature)) {
2301 double aWidth = thePrs->width();
2302 thePrs->setWidth(aWidth / 2.5);
2305 double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
2306 thePrs->setDeflection(aDeflection);
2309 //*************************************************************************************
2310 void PartSet_Fitter::fitAll(Handle(V3d_View) theView)
2312 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
2314 ModuleBase_IWorkshop* aWorkshop = mySketchMgr->module()->workshop();
2315 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
2316 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
2319 int aNumberOfSubs = aSketch->numberOfSubs();
2320 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2321 for (int i = 0; i < aNumberOfSubs; i++) {
2322 FeaturePtr aFeature = aSketch->subFeature(i);
2323 if (aDisplayer->isVisible(aFeature)) {
2324 AISObjectPtr aAisPtr = aDisplayer->getAISObject(aFeature);
2325 Handle(AIS_InteractiveObject) aAisObj = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2326 if (!aAisObj->IsInfinite()) {
2328 aAisObj->BoundingBox(aBox);
2333 std::list<ResultPtr> aResults = aFeature->results();
2334 std::list<ResultPtr>::const_iterator aIt;
2336 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
2338 if (aRes->isDisplayed()) {
2339 FeaturePtr aFeature = ModelAPI_Feature::feature(aRes);
2340 if (aFeature.get()) {
2341 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2342 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
2343 if (aSPFeature.get()) {
2345 aSPFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
2346 if (!(aSPFeature->isExternal() || isAxiliary)) {
2347 GeomShapePtr aShape = aRes->shape();
2348 aShape->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2350 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2359 if (aBndBox.IsVoid())
2362 theView->FitAll(aBndBox, 0.01);