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),
176 myIsSketchStarted(false)
178 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
179 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
181 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
183 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
184 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
186 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
187 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
189 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
190 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
192 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
193 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
195 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
196 XGUI_Workshop* aWorkshop = aConnector->workshop();
197 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
199 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
200 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
201 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
203 mySketchPlane = new PartSet_PreviewSketchPlane();
205 registerSelectionFilter(SF_SketchCirclePointFilter, new PartSet_CirclePointFilter(anIWorkshop));
206 registerSelectionFilter(SF_SketchPlaneFilter, new ModuleBase_ShapeInPlaneFilter());
208 Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_DOF_OBJECTS));
211 PartSet_SketcherMgr::~PartSet_SketcherMgr()
213 delete mySketchPlane;
216 void PartSet_SketcherMgr::onEnterViewPort()
218 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
219 // created feature because it should be done in onMouseMove(). Some widgets watch
220 // the mouse move and use the cursor position to update own values. If the presentaion is
221 // redisplayed before this update, the feature presentation jumps from reset value to current.
222 myIsMouseOverWindow = true;
224 #ifdef DEBUG_DO_NOT_BY_ENTER
228 // It is switched off because of
229 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
230 // if (canChangeCursor(getCurrentOperation())) {
231 // QCursor* aCurrentCursor = QApplication::overrideCursor();
232 // if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
233 // QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
234 //#ifdef DEBUG_CURSOR
235 // qDebug("onEnterViewPort() : Qt::CrossCursor");
240 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
243 operationMgr()->onValidateOperation();
245 // we need change displayed state of the current operation feature
246 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
247 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
248 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
249 // presentation becomes valid and redisplay happens
250 //ModuleBase_Operation* aOperation = getCurrentOperation();
251 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
252 (getCurrentOperation());
254 FeaturePtr aFeature = aFOperation->feature();
255 if (aFeature.get() && aFeature->data()->isValid()) {
256 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
261 void PartSet_SketcherMgr::onLeaveViewPort()
263 myIsMouseOverViewProcessed = false;
264 myIsMouseOverWindow = false;
266 #ifdef DEBUG_DO_NOT_BY_ENTER
270 // if (canChangeCursor(getCurrentOperation())) {
271 // QApplication::restoreOverrideCursor();
272 //#ifdef DEBUG_CURSOR
273 // qDebug("onLeaveViewPort() : None");
277 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
280 // the method should be performed if the popup menu is called,
281 // the reset of the current widget should not happen
282 if (myIsPopupMenuActive)
285 // it is important to validate operation here only if sketch entity create operation is active
286 // because at this operation we reacts to the mouse leave/enter view port
287 operationMgr()->onValidateOperation();
289 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
290 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
291 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
292 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
293 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
294 // obtained after reset value
295 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
296 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
298 anActiveWidget->reset();
300 // hides the presentation of the current operation feature
301 // the feature is to be erased here, but it is correct to call canDisplayObject because
302 // there can be additional check (e.g. editor widget in distance constraint)
303 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
304 (getCurrentOperation());
306 FeaturePtr aFeature = aFOperation->feature();
307 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
309 // we should update viewer after the presentation are hidden in the viewer
310 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
311 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
315 //Temporary commented as we do not modify values in property panel
316 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
318 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
319 myModule->sketchReentranceMgr()->isInternalEditActive())
321 // it is necessary to save current selection in order to restore it after the values are modifed
322 storeSelection(ST_SelectAndHighlightType);
324 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
325 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
326 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
327 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
330 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
332 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
333 myModule->sketchReentranceMgr()->isInternalEditActive()) {
334 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
337 // it is necessary to restore current selection in order to restore it after values are modified
339 myCurrentSelection.clear();
341 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
342 // viewer happens by deselect/select the modified objects. The flag should be restored after
343 // the selection processing. The update viewer should be also called.
344 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
345 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
346 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
347 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
348 aDisplayer->updateViewer();
352 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
354 // Clear dragging mode
355 myIsDragging = false;
357 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
359 //get2dPoint(theWnd, theEvent, myClickedPoint);
360 if (!(theEvent->buttons() & Qt::LeftButton))
363 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
364 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
365 //if (!aViewer->canDragByMouse())
368 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
369 (getCurrentOperation());
373 bool isEditing = aFOperation->isEditOperation();
374 bool aCanDrag = aViewer->canDragByMouse();
376 //if (!aViewer->canDragByMouse() && isEditing) {
377 // // Do not edit by dragging
382 // If the current widget is a selector, do nothing, it processes the mouse press
383 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
384 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
389 // Use only for sketch operations
390 if (myCurrentSketch) {
391 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
394 bool isSketcher = isSketchOperation(aFOperation);
395 bool isSketchOpe = isNestedSketchOperation(aFOperation);
397 // Avoid non-sketch operations
398 if ((!isSketchOpe) && (!isSketcher))
401 // Ignore creation sketch operation
402 if ((!isSketcher) && (!isEditing))
405 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
406 storeSelection(aHasShift ? ST_SelectAndHighlightType : ST_HighlightType, myCurrentSelection);
408 if (myCurrentSelection.empty()) {
409 if (isSketchOpe && (!isSketcher))
410 // commit previous operation
411 if (!aFOperation->commit())
412 aFOperation->abort();
415 // Init flyout point for radius rotation
416 FeaturePtr aFeature = myCurrentSelection.begin().key();
418 get2dPoint(theWnd, theEvent, myCurrentPoint);
424 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
426 if (aFeature.get() != NULL) {
427 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
428 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
429 if (aSPFeature.get() &&
430 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
431 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
432 DataPtr aData = aSPFeature->data();
433 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
434 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
435 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
436 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
439 } else if (isSketchOpe && isEditing) {
440 // If selected another object commit current result
441 bool aPrevLaunchingState = myIsEditLaunching;
442 /// store editing state for Edit operation in order to do not clear highlight by restart
443 /// of edit operation.
444 /// Internal edit should not be stored as editing operation as the result will be a
445 /// creation operation, where previous selection should not be used(and will be cleared)
446 myIsEditLaunching = !myModule->sketchReentranceMgr()->isInternalEditActive();
447 aFOperation->commit();
453 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
455 myIsEditLaunching = aPrevLaunchingState;
456 if (aFeature.get() != NULL) {
457 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
458 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
459 if (aSPFeature.get() &&
460 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
461 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
462 DataPtr aData = aSPFeature->data();
463 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
464 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
465 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
466 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
473 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
475 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
476 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
478 aViewer->enableDrawMode(myPreviousDrawModeEnabled);
480 bool aWasDragging = myIsDragging;
481 myIsDragging = false;
483 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent)) {
486 // if mouse is pressed when it was over view and at release the mouse is out of view, do nothing
487 if (!myIsMouseOverViewProcessed) {
490 //if (!aViewer->canDragByMouse())
492 ModuleBase_OperationFeature* aOp =
493 dynamic_cast<ModuleBase_OperationFeature*>(getCurrentOperation());
495 bool aStartNoDragOperation = !aViewer->canDragByMouse() && aOp->isEditOperation();
496 if (aStartNoDragOperation || myNoDragMoving) {
497 // Process edit operation without dragging
498 if (myCurrentSelection.size() > 0)
499 myNoDragMoving = !myNoDragMoving;
501 myNoDragMoving = false;
505 restoreSelection(myCurrentSelection);
506 myCurrentSelection.clear();
510 if (isNestedSketchOperation(aOp)) {
511 // Only for sketcher operations
514 /// the previous selection is lost by mouse release in the viewer(Select method), but
515 /// it is still stored in myCurrentSelection. So, it is possible to restore selection
516 /// It is important for drag(edit with mouse) of sketch entities.
517 restoreSelection(myCurrentSelection);
518 myCurrentSelection.clear();
526 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
527 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
529 aProcessor->mouseReleased(theWnd, theEvent);
532 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
534 #ifdef DEBUG_SKETCH_ENTITIES_ON_MOVE
535 CompositeFeaturePtr aSketch = activeSketch();
537 std::cout << "mouse move SKETCH FEATURES [" << aSketch->numberOfSubs() << "]:" << std::endl;
539 for (int i = 0, aNbSubs = aSketch->numberOfSubs(); i < aNbSubs; i++) {
540 //std::cout << getFeatureInfo(aSketch->subFeature(i), false) << std::endl;
541 anInfo.append(ModuleBase_Tools::objectInfo(aSketch->subFeature(i)));
543 QString anInfoStr = anInfo.join("\n");
544 qDebug(QString("%1").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
547 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
550 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
551 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
552 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
554 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
555 #ifdef DRAGGING_DEBUG
559 // 1. perform the widget mouse move functionality and display the presentation
560 // the mouse move should be processed in the widget, if it can in order to visualize correct
561 // presentation. These widgets correct the feature attribute according to the mouse position
562 ModuleBase_ModelWidget* anActiveWidget = myModule->activeWidget();
563 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
565 aProcessor->mouseMoved(theWnd, theEvent);
566 if (!myIsMouseOverViewProcessed) {
567 myIsMouseOverViewProcessed = true;
569 // the feature is to be erased here, but it is correct to call canDisplayObject because
570 // there can be additional check (e.g. editor widget in distance constraint)
571 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
572 (getCurrentOperation());
574 FeaturePtr aFeature = aFOperation->feature();
575 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
578 aDisplayer->updateViewer();
579 #ifdef DRAGGING_DEBUG
580 cout << "Mouse move processing " << t.elapsed() << endl;
583 //myClickedPoint.clear();
585 if (myIsDragging || myNoDragMoving) {
586 // 1. the current selection is saved in the mouse press method in order to restore it after
588 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
589 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
590 // deselected). This flag should be restored in the slot, processed the mouse release signal.
591 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
592 if (!aCurrentOperation)
594 if (isSketchOperation(aCurrentOperation))
595 return; // No edit operation activated
597 #ifdef DRAGGING_DEBUG
602 Handle(V3d_View) aView = theWnd->v3dView();
603 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
605 get2dPoint(theWnd, theEvent, aMousePnt);
607 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
608 new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
609 std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
610 new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
612 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
613 // viewer happens by deselect/select the modified objects. The flag should be restored after
614 // the selection processing. The update viewer should be also called.
615 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
617 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
618 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
619 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
620 aLast = myCurrentSelection.end();
621 // 4. the features and attributes modification(move)
622 bool isModified = false;
623 for (; anIt != aLast; anIt++) {
624 FeaturePtr aFeature = anIt.key();
626 std::set<AttributePtr> anAttributes = anIt.value().myAttributes;
627 // Process selection by attribute: the priority to the attribute
628 if (!anAttributes.empty()) {
629 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
630 anAttLast = anAttributes.end();
631 for (; anAttIt != anAttLast; anAttIt++) {
632 AttributePtr anAttr = *anAttIt;
633 if (anAttr.get() == NULL)
635 std::string aAttrId = anAttr->id();
636 DataPtr aData = aFeature->data();
637 if (aData->isValid()) {
638 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
639 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
640 if (aPoint.get() != NULL) {
641 bool isImmutable = aPoint->setImmutable(true);
643 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
644 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
645 aMessage->setMovedAttribute(aPoint);
646 aMessage->setOriginalPosition(anOriginalPosition);
647 aMessage->setCurrentPosition(aCurrentPosition);
648 Events_Loop::loop()->send(aMessage);
651 aPoint->setImmutable(isImmutable);
657 // Process selection by feature
658 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
659 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
660 if (aSketchFeature) {
661 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
662 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
663 aMessage->setMovedObject(aFeature);
664 aMessage->setOriginalPosition(anOriginalPosition);
665 aMessage->setCurrentPosition(aCurrentPosition);
666 Events_Loop::loop()->send(aMessage);
671 // the modified state of the current operation should be updated if there are features, which
674 aCurrentOperation->onValuesChanged();
675 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
677 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
679 // 5. it is necessary to save current selection in order to restore it after the features moving
680 restoreSelection(myCurrentSelection);
681 // 6. restore the update viewer flag and call this update
682 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
683 aDisplayer->updateViewer();
685 #ifdef DRAGGING_DEBUG
686 cout << "Mouse move processing " << t.elapsed() << endl;
690 myCurrentPoint = aMousePnt;
694 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
696 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
697 (getCurrentOperation());
698 if (aFOperation && aFOperation->isEditOperation()) {
699 std::string aId = aFOperation->id().toStdString();
700 if (isDistanceOperation(aFOperation))
702 // Activate dimension value editing on double click
703 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
704 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
705 // Find corresponded widget to activate value editing
706 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
707 std::string anId = aWgt->attributeID();
708 if (anId == SketchPlugin_Constraint::VALUE() ||
709 anId == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() ||
710 anId == SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()) {
711 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
713 anEditor->showPopupEditor();
721 void PartSet_SketcherMgr::onApplicationStarted()
723 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
724 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
725 XGUI_Workshop* aWorkshop = aConnector->workshop();
726 PartSet_SketcherReentrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
728 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
729 if (aPropertyPanel) {
730 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
731 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
733 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
734 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
735 //connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
736 // aReentranceMgr, SLOT(onWidgetActivated()));
739 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
740 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
741 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
743 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
744 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
745 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
748 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
750 //if (!myClickedPoint.myIsInitialized)
753 //ModuleBase_Operation* aOperation = getCurrentOperation();
754 // the distance constraint feature should not use the clickedd point
755 // this is workaround in order to don't throw down the flyout point value,
756 // set by execute() method of these type of features
757 //if (isDistanceOperation(aOperation))
760 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
762 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
766 void PartSet_SketcherMgr::onBeforeContextMenu()
768 myIsPopupMenuActive = true;
771 void PartSet_SketcherMgr::onAfterContextMenu()
773 myIsPopupMenuActive = false;
776 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
779 Handle(V3d_View) aView = theWnd->v3dView();
780 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
782 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
783 thePoint.setValue(aX, anY);
786 void PartSet_SketcherMgr::launchEditing()
788 if (!myCurrentSelection.empty()) {
789 FeaturePtr aFeature = myCurrentSelection.begin().key();
790 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
791 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
793 if (!aSPFeature->isExternal())
794 myModule->editFeature(aSPFeature);
796 // need to edit a feature (Projection/IntersectionPoint),
797 // which produces current External feature
798 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
799 SketchPlugin_Projection::ID());
800 if (!aProducerFeature.get())
801 aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
802 SketchPlugin_IntersectionPoint::ID());
803 if (aProducerFeature.get())
804 myModule->editFeature(aProducerFeature);
810 bool PartSet_SketcherMgr::sketchSolverError()
812 bool anError = false;
813 CompositeFeaturePtr aSketch = activeSketch();
815 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
816 anError = !aAttributeString->value().empty();
821 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
824 if (!theFeature.get() || !theFeature->data()->isValid())
827 CompositeFeaturePtr aSketch = activeSketch();
828 if (aSketch.get() && aSketch == theFeature) {
829 std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
830 anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
835 void PartSet_SketcherMgr::clearClickedFlags()
837 //myClickedPoint.clear();
838 myCurrentPoint.clear();
841 const QStringList& PartSet_SketcherMgr::replicationsIdList()
843 static QStringList aReplicationIds;
844 if (aReplicationIds.size() == 0) {
845 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
846 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
847 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
849 return aReplicationIds;
852 const QStringList& PartSet_SketcherMgr::constraintsIdList()
854 static QStringList aConstraintIds;
855 if (aConstraintIds.size() == 0) {
856 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
857 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
858 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
859 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
860 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
861 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
862 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
863 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
864 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
865 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
866 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
867 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
868 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
869 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
870 aConstraintIds << SketchPlugin_ConstraintMirror::ID().c_str();
871 aConstraintIds << SketchPlugin_MultiTranslation::ID().c_str();
872 aConstraintIds << SketchPlugin_MultiRotation::ID().c_str();
873 aConstraintIds << SketchPlugin_ConstraintDistanceAlongDir::ID().c_str();
874 aConstraintIds << SketchPlugin_ConstraintDistanceHorizontal::ID().c_str();
875 aConstraintIds << SketchPlugin_ConstraintDistanceVertical::ID().c_str();
877 return aConstraintIds;
880 void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSketch,
883 if (!theSketch.get() || !PartSet_Tools::sketchPlane(theSketch).get())
886 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
887 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
888 theModes.append(SketcherPrs_Tools::Sel_Constraint);
889 theModes.append(TopAbs_VERTEX);
890 theModes.append(TopAbs_EDGE);
893 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ObjectPtr& theObj)
895 Handle(AIS_InteractiveObject) aPrs;
897 FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
898 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
899 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
901 aPrs = new PartSet_ResultSketchPrs(aResult);
906 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
908 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
911 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
913 bool aNestedSketch = false;
915 FeaturePtr anActiveSketch = activeSketch();
916 if (anActiveSketch.get() && theOperation) {
917 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
918 anActiveSketch->getKind().c_str());
919 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
921 if (aSketchOperation && aFOperation) {
922 FeaturePtr aFeature = aFOperation->feature();
923 if (aFeature.get()) {
924 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
925 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
929 return aNestedSketch;
932 bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const
934 bool aNestedSketch = false;
936 FeaturePtr anActiveSketch = activeSketch();
937 if (anActiveSketch.get()) {
938 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
939 anActiveSketch->getKind().c_str());
940 if (aSketchOperation) {
941 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
942 aNestedSketch = aGrantedOpIds.contains(theFeatureKind);
945 return aNestedSketch;
948 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
949 const CompositeFeaturePtr& theSketch) const
951 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
953 return aFOperation && !aFOperation->isEditOperation() &&
954 isNestedSketchOperation(aFOperation);
957 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
958 const CompositeFeaturePtr& theSketch) const
960 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
962 return aFOperation && aFOperation->isEditOperation() &&
963 isNestedSketchOperation(aFOperation);
966 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
968 return (theId == SketchPlugin_Line::ID()) ||
969 (theId == SketchPlugin_Point::ID()) ||
970 (theId == SketchPlugin_Arc::ID()) ||
971 (theId == SketchPlugin_Circle::ID()) ||
972 (theId == SketchPlugin_Ellipse::ID()) ||
973 (theId == SketchPlugin_EllipticArc::ID());
976 bool PartSet_SketcherMgr::isExternalFeature(const FeaturePtr& theFeature)
978 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
979 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
980 return aSPFeature.get() && aSPFeature->isExternal();
983 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
985 std::string anId = theOperation ? theOperation->id().toStdString() : "";
987 return isDistanceKind(anId);
990 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
992 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
993 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
994 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
995 (theKind == SketchPlugin_ConstraintAngle::ID()) ||
996 (theKind == SketchPlugin_ConstraintDistanceHorizontal::ID()) ||
997 (theKind == SketchPlugin_ConstraintDistanceVertical::ID()) ||
998 (theKind == SketchPlugin_ConstraintDistanceAlongDir::ID());
1001 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
1003 static Events_ID EVENT_ATTR = Events_Loop::loop()->eventByName(EVENT_VISUAL_ATTRIBUTES);
1004 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1006 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1007 (getCurrentOperation());
1011 myIsSketchStarted = true;
1012 SketcherPrs_Tools::setPixelRatio(ModuleBase_Tools::currentPixelRatio());
1014 myModule->onViewTransformed();
1016 // Display all sketcher sub-Objects
1017 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
1018 double aSizeOfView = 0;
1019 std::shared_ptr<GeomAPI_Pnt> aCentralPoint;
1020 if (aFOperation->isEditOperation() &&
1021 mySketchPlane->getDefaultSizeOfView(myCurrentSketch, aSizeOfView, aCentralPoint)) {
1022 mySketchPlane->setSizeOfView(aSizeOfView, true, aCentralPoint);
1025 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
1026 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1028 // Hide sketcher result
1029 std::list<ResultPtr> aResults = myCurrentSketch->results();
1030 std::list<ResultPtr>::const_iterator aIt;
1031 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1032 (*aIt)->setDisplayed(false);
1034 myCurrentSketch->setDisplayed(false);
1036 // Remove invalid sketch entities
1037 std::set<FeaturePtr> anInvalidFeatures;
1038 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
1039 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1040 for (int i = 0; i < aNumberOfSubs; i++) {
1041 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1042 if (aFeature.get()) {
1043 if (!aFactory->validate(aFeature))
1044 anInvalidFeatures.insert(aFeature);
1047 if (!anInvalidFeatures.empty()) {
1048 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1049 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
1051 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
1052 aLast = anInvalidFeatures.end();
1053 // separate features to references to parameter features and references to others
1054 QStringList anInvalidFeatureNames;
1055 for (; anIt != aLast; anIt++) {
1056 FeaturePtr aFeature = *anIt;
1058 anInvalidFeatureNames.append(aFeature->name().c_str());
1060 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
1061 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
1062 std::set<FeaturePtr> aFeatureRefsToDelete;
1063 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
1064 aFeatureRefsToDelete, aPrefixInfo)) {
1065 if (!aFeatureRefsToDelete.empty())
1066 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1067 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
1068 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1069 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
1070 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
1074 // update state of overconstraint listener should be done before sketch features/results
1075 // display (as the display will ask custom color from the listener)
1076 myModule->overconstraintListener()->setActive(true);
1077 // Display sketcher objects
1079 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1080 aNumberOfSubs = myCurrentSketch->numberOfSubs();
1081 for (int i = 0; i < aNumberOfSubs; i++) {
1082 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1083 #ifdef DEBUG_SKETCHER_ENTITIES
1084 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1086 std::list<ResultPtr> aResults = aFeature->results();
1087 std::list<ResultPtr>::const_iterator aIt;
1088 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1089 if ((*aIt)->isDisplayed())
1090 // Display object if it was created outside of GUI
1091 aECreator->sendUpdated((*aIt), EVENT_DISP);
1093 (*aIt)->setDisplayed(true);
1095 if (aFeature->isDisplayed())
1096 aECreator->sendUpdated(aFeature, EVENT_DISP);
1098 aFeature->setDisplayed(true);
1099 aECreator->sendUpdated(aFeature, EVENT_ATTR);
1101 #ifdef DEBUG_SKETCHER_ENTITIES
1102 QString anInfoStr = anInfo.join(";\t");
1103 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1106 bool aHasPlane = false;
1107 std::shared_ptr<GeomAPI_Pln> aPln;
1108 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1109 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1110 if (!aFilter.IsNull())
1111 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1113 workshop()->selectionActivate()->updateSelectionFilters();
1114 workshop()->selectionActivate()->updateSelectionModes();
1116 Events_Loop::loop()->flush(EVENT_DISP);
1117 Events_Loop::loop()->flush(EVENT_ATTR);
1119 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1121 workshop()->viewer()->set2dMode(true);
1123 PartSet_Fitter* aFitter = new PartSet_Fitter(this);
1124 myModule->workshop()->viewer()->setFitter(aFitter);
1127 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1129 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1130 PartSet_Fitter* aFitter = (PartSet_Fitter*)myModule->workshop()->viewer()->fitter();
1131 myModule->workshop()->viewer()->setFitter(0);
1134 myIsSketchStarted = false;
1136 myIsMouseOverWindow = false;
1137 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1138 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1139 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1141 if (myExternalPointsMgr) {
1142 delete myExternalPointsMgr;
1143 myExternalPointsMgr = 0;
1145 onShowPoints(false);
1147 DataPtr aData = myCurrentSketch->data();
1148 if (!aData->isValid()) {
1149 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1150 // The sketch was aborted
1151 myCurrentSketch = CompositeFeaturePtr();
1152 mySketchPlane->eraseSketchPlane(myModule->workshop());
1154 // Erase all sketcher objects
1155 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1156 foreach (ObjectPtr aObj, aObjects) {
1157 DataPtr aObjData = aObj->data();
1158 if (!aObjData->isValid())
1159 aObj->setDisplayed(false);
1163 // Hide all sketcher sub-Objects
1164 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1165 for (int i = 0; i < aNumberOfSubs; i++) {
1166 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1167 std::list<ResultPtr> aResults = aFeature->results();
1168 std::list<ResultPtr>::const_iterator aIt;
1169 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1170 (*aIt)->setDisplayed(false);
1172 aFeature->setDisplayed(false);
1174 // Display sketcher result
1175 std::list<ResultPtr> aResults = myCurrentSketch->results();
1176 std::list<ResultPtr>::const_iterator aIt;
1177 Events_Loop* aLoop = Events_Loop::loop();
1178 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1180 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1182 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1183 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1184 (*aIt)->setDisplayed(true);
1185 // this display event is needed because sketch already may have "displayed" state,
1186 // but not displayed while it is still active (issue 613, abort of existing sketch)
1187 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1190 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1191 myCurrentSketch->setDisplayed(true);
1193 myCurrentSketch = CompositeFeaturePtr();
1194 mySketchPlane->eraseSketchPlane(myModule->workshop());
1196 Events_Loop::loop()->flush(aDispEvent);
1198 workshop()->selectionActivate()->updateSelectionFilters();
1199 workshop()->selectionActivate()->updateSelectionModes();
1200 workshop()->viewer()->set2dMode(false);
1203 //void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1205 // if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1206 // QCursor* aCurrentCursor = QApplication::overrideCursor();
1207 // if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1208 // QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
1209 //#ifdef DEBUG_CURSOR
1210 // qDebug("startNestedSketch() : Qt::CrossCursor");
1216 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1218 myIsMouseOverViewProcessed = true;
1219 operationMgr()->onValidateOperation();
1220 // when sketch nested operation is stopped the cursor should be restored unconditionally
1221 //if (canChangeCursor(theOperation)) {
1222 //QApplication::restoreOverrideCursor();
1224 qDebug("stopNestedSketch() : None");
1227 /// improvement to deselect automatically all eventual selected objects, when
1228 // returning to the neutral point of the Sketcher
1229 bool isClearSelectionPossible = true;
1230 if (myIsEditLaunching) {
1231 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1234 FeaturePtr aFeature = aFOperation->feature();
1235 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1236 isClearSelectionPossible = false;
1240 if (isClearSelectionPossible)
1241 workshop()->selector()->clearSelection();
1242 if (myPointsHighlight.size())
1246 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1248 if (isNestedCreateOperation(theOperation, activeSketch())) {
1249 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1252 FeaturePtr aFeature = aFOperation->feature();
1253 // it is necessary to check the the feature data validity because
1254 // some kind of features are removed by an operation commit(the macro state of a feature)
1255 if (aFeature.get() && aFeature->data()->isValid()) {
1256 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1262 bool PartSet_SketcherMgr::sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType)
1264 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1267 void PartSet_SketcherMgr::registerSelectionFilter(
1268 const ModuleBase_SelectionFilterType theFilterType, const Handle(SelectMgr_Filter)& theFilter)
1270 mySelectionFilterTypes.insert(theFilterType);
1271 myModule->registerSelectionFilter(theFilterType, theFilter);
1274 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1276 bool isOperationStopped = false;
1277 ModuleBase_Operation* anOperation = getCurrentOperation();
1278 if(anOperation && isNestedSketchOperation(anOperation)) {
1279 // Set final definitions if they are necessary
1280 //propertyPanelDefined(aOperation);
1281 /// Commit sketcher operations automatically
1282 /// distance operation are able to show popup editor to modify the distance value
1283 /// after entering the value, the operation should be committed/aborted(by Esc key)
1284 bool aCanCommitOperation = true;
1285 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1287 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1288 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1289 aCanCommitOperation);
1290 if (!aValueAccepted)
1291 return isOperationStopped;
1294 if (aCanCommitOperation)
1295 isOperationStopped = anOperation->commit();
1297 anOperation->abort();
1298 isOperationStopped = true;
1301 return isOperationStopped;
1304 bool PartSet_SketcherMgr::canUndo() const
1306 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1309 bool PartSet_SketcherMgr::canRedo() const
1311 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1314 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1316 bool aCanErase = true;
1317 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1318 if (myCurrentSketch.get()) {
1319 return !isObjectOfSketch(theObject);
1324 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1326 bool aCanDisplay = true;
1328 bool aHasActiveSketch = activeSketch().get() != NULL;
1329 if (aHasActiveSketch) {
1330 // 1. the sketch feature should not be displayed during the sketch active operation
1331 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1332 // nested features can be visualized
1333 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1334 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1335 aCanDisplay = false;
1337 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1338 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1339 /// some sketch entities should be never shown, e.g. projection feature
1340 if (aSketchFeature.get())
1341 aCanDisplay = aSketchFeature->canBeDisplayed();
1343 else { // there are no an active sketch
1344 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1345 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1346 if (aFeature.get() != NULL) {
1347 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1348 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1349 if (aSketchFeature.get()) {
1350 aCanDisplay = false;
1355 // 3. the method should not filter the objects, which are not related to the current operation.
1356 // The object is filtered just if it is a current operation feature or this feature result
1358 bool isObjectFound = false;
1359 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1360 (getCurrentOperation());
1362 FeaturePtr aFeature = aFOperation->feature();
1363 if (aFeature.get()) {
1364 std::list<ResultPtr> aResults = aFeature->results();
1365 if (theObject == aFeature)
1366 isObjectFound = true;
1368 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1369 for (; anIt != aLast && !isObjectFound; anIt++) {
1370 isObjectFound = *anIt == theObject;
1375 if (isObjectFound) {
1376 // 4. For created nested feature operation do not display the created feature if
1377 // the mouse curstor leaves the OCC window.
1378 // The correction cases, which ignores this condition:
1379 // a. the property panel values modification
1380 // b. the popup menu activated
1381 // c. widget editor control
1382 #ifndef DEBUG_DO_NOT_BY_ENTER
1383 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1384 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1385 ModuleBase_WidgetEditor* anEditorWdg =
1386 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1387 // the active widget editor should not influence here. The presentation should be visible
1388 // always when this widget is active.
1389 if (!anEditorWdg && !myIsPopupMenuActive) {
1390 // during a nested create operation, the feature is redisplayed only
1391 // if the mouse over view
1392 // of there was a value modified in the property panel after the mouse left the view
1393 aCanDisplay = canDisplayCurrentCreatedFeature();
1400 // checks the sketcher constraints visibility according to active sketch check box states
1402 bool aProcessed = false;
1403 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1404 if (aFeature.get()) {
1405 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1407 aCanDisplay = aConstraintDisplayed;
1414 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1415 const PartSet_Tools::ConstraintVisibleState& theState,
1416 bool& isProcessed) const
1418 bool aSwitchedOn = true;
1420 const QStringList& aConstrIds = constraintsIdList();
1422 std::string aKind = theFeature->getKind();
1423 if (aConstrIds.contains(QString(aKind.c_str()))) {
1424 bool isTypedConstraint = false;
1427 case PartSet_Tools::Dimensional: {
1428 bool isDistance = isDistanceKind(aKind);
1431 aSwitchedOn = myIsConstraintsShown[theState];
1435 case PartSet_Tools::Geometrical: {
1436 bool isGeometrical = !isDistanceKind(aKind);
1437 if (isGeometrical) {
1439 aSwitchedOn = myIsConstraintsShown[theState];
1443 case PartSet_Tools::Any: {
1445 bool isDistance = isDistanceKind(aKind);
1447 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1449 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1459 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1461 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1462 (getCurrentOperation());
1463 if (aFOperation && myCurrentSketch.get()) {
1464 // find results of the current operation
1465 // these results should not be proposed to be deleted
1466 FeaturePtr anOperationFeature = aFOperation->feature();
1467 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1468 std::set<ResultPtr> anOperationResults;
1469 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1470 aRLast = anOperationResultList.end();
1471 for (; aRIt != aRLast; aRIt++)
1472 anOperationResults.insert(*aRIt);
1474 std::set<FeaturePtr> anObjectsToBeDeleted;
1475 QStringList anObjectsToBeDeletedNames;
1476 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1477 for (; anIt != aLast; anIt++) {
1478 ObjectPtr anObject = *anIt;
1479 bool aCanErase = true;
1480 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1481 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1482 // the result is found between current feature results
1483 if (anOperationResults.find(aResult) != anOperationResults.end())
1486 if (aResult.get()) {
1487 // Display sketcher objects
1488 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1489 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1490 std::list<ResultPtr> aResults = aFeature->results();
1491 std::list<ResultPtr>::const_iterator anIt;
1492 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1493 aCanErase = *anIt != aResult;
1498 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1499 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1500 anObjectsToBeDeleted.insert(aFeature);
1501 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1505 if (!anObjectsToBeDeleted.empty()) {
1506 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1507 QString aMessage = tr("The following features have incorrect presentation and \
1508 will be hidden: %1. Would you like to delete them?")
1509 .arg(aFeatureNames);
1510 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1511 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1512 QMessageBox::Cancel);
1513 if (anAnswer == QMessageBox::Ok) {
1514 QObjectPtrList anObjects;
1515 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1516 aLast = anObjectsToBeDeleted.end();
1517 for (; anIt != aLast; anIt++)
1518 anObjects.append(*anIt);
1519 SessionPtr aMgr = ModelAPI_Session::get();
1520 DocumentPtr aDoc = aMgr->activeDocument();
1521 bool aIsOp = aMgr->isOperation();
1523 aMgr->startOperation();
1524 workshop()->deleteFeatures(anObjects);
1525 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1526 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1527 //Events_Loop::loop()->flush(aDeletedEvent);
1528 //Events_Loop::loop()->flush(aRedispEvent);
1531 aMgr->finishOperation();
1537 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1539 bool aCanDisplay = myIsMouseOverWindow;
1541 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1543 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1548 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1550 return isNestedCreateOperation(theOperation, activeSketch()) ||
1551 myModule->sketchReentranceMgr()->isInternalEditActive();
1554 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1556 return myIsConstraintsShown;
1559 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1561 bool isFoundObject = false;
1563 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1564 if (anObjectFeature.get()) {
1565 int aSize = myCurrentSketch->numberOfSubs();
1566 for (int i = 0; i < aSize && !isFoundObject; i++) {
1567 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1568 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1571 return isFoundObject;
1574 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1576 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1577 if (!aFilter.IsNull())
1578 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1580 workshop()->selectionActivate()->updateSelectionModes();
1583 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1584 ModuleBase_IWorkshop* theWorkshop,
1585 bool& theCanCommitOperation)
1587 bool isValueAccepted = false;
1588 theCanCommitOperation = false;
1590 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1592 FeaturePtr aFeature = aFOperation->feature();
1593 // editor is shown only if all attribute references are filled by preseletion
1594 bool anAllRefAttrInitialized = true;
1596 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1597 ModelAPI_AttributeRefAttr::typeId());
1598 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1599 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1600 anAllRefAttrInitialized = (*anIt)->isInitialized();
1602 if (anAllRefAttrInitialized) {
1603 // Activate dimension value editing on double click
1604 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1605 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1606 // Find corresponded widget to activate value editing
1607 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1608 if (aWgt->attributeID() == "ConstraintValue") {
1609 // the featue should be displayed in order to find the AIS text position,
1610 // the place where the editor will be shown
1611 aFeature->setDisplayed(true);
1612 /// the execute is necessary to perform in the feature compute for flyout position
1613 aFeature->execute();
1615 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1616 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1618 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1620 int aX = 0, anY = 0;
1622 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1623 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1624 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1625 Handle(AIS_InteractiveObject) anAISIO;
1626 if (anAIS.get() != NULL) {
1627 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1629 if (anAIS.get() != NULL) {
1630 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1632 if (!anAISIO.IsNull()) {
1633 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1634 if (!aDim.IsNull()) {
1635 gp_Pnt aPosition = aDim->GetTextPosition();
1637 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1638 Handle(V3d_View) aView = aViewer->activeView();
1640 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1642 QWidget* aViewPort = aViewer->activeViewPort();
1643 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1648 anEditor->setCursorPosition(aX, anY);
1649 isValueAccepted = anEditor->showPopupEditor(false);
1650 theCanCommitOperation = true;
1656 return isValueAccepted;
1659 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1660 const FeaturePtr& theSketch,
1661 ModuleBase_IWorkshop* theWorkshop,
1662 const FeatureToSelectionMap& theSelection,
1663 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1665 if (theFeature.get() == NULL)
1668 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1669 SelectionInfo anInfo = anIt.value();
1670 std::set<AttributePtr> aSelectedAttributes = anInfo.myAttributes;
1671 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1673 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1675 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1676 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1678 // 1. found the feature's owners. Check the AIS objects of the constructions
1679 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1680 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1681 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1683 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1684 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1685 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1686 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1687 if (!anOwner.IsNull())
1688 theOwnersToSelect.Add(anOwner);
1692 // 2. found the feature results's owners
1693 std::list<ResultPtr> aResults = theFeature->results();
1694 std::list<ResultPtr>::const_iterator aIt;
1696 bool isSameShape = false;
1697 if (aResults.size() > 0) {
1698 ResultPtr aFirstResult = theFeature->firstResult();
1699 if (aFirstResult.get() && aFirstResult->shape().get()) {
1700 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1701 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1704 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1705 ResultPtr aResult = *aIt;
1706 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1707 if (aAISObj.get() == NULL)
1709 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1711 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1712 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1713 bool aFoundLocalShape = false;
1714 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1715 Handle(StdSelect_BRepOwner) anOwner =
1716 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1717 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1719 const TopoDS_Shape& aShape = anOwner->Shape();
1720 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1721 if (aShapeType == TopAbs_VERTEX) {
1722 AttributePtr aPntAttr =
1723 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1724 if (aPntAttr.get() != NULL &&
1725 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end())
1726 theOwnersToSelect.Add(anOwner);
1727 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1728 theOwnersToSelect.Add(anOwner);
1731 else if (aShapeType == TopAbs_EDGE) {
1732 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1733 // try to restore local selection on Shape result
1734 // we can do this only if the shape was not changed
1735 theOwnersToSelect.Add(anOwner);
1736 aFoundLocalShape = true;
1741 if (!aFoundLocalShape) {
1742 // result owners are put in the list of selection only if local selected shapes were not
1744 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1745 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1746 Handle(StdSelect_BRepOwner) anOwner =
1747 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1748 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1750 // select whole result
1751 theOwnersToSelect.Add(anOwner);
1758 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1759 const bool isToConnect)
1761 //Temporary commented as we do not modify values in property panel
1763 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1764 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1765 //connect(theWidget, SIGNAL(afterValuesChanged()),
1766 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1767 connect(theWidget, SIGNAL(afterValuesChanged()),
1768 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1771 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1772 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1773 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1774 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1775 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1776 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1780 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1782 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1783 (getCurrentOperation());
1785 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1786 isNestedSketchOperation(aFOperation) &&
1787 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1788 FeaturePtr aFeature = aFOperation->feature();
1789 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1794 //void PartSet_SketcherMgr::customisePresentation(const ObjectPtr& theObject)
1796 // ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1797 // (getCurrentOperation());
1798 // if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1799 // isNestedSketchOperation(aFOperation)))
1800 // SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1802 // // update entities selection priorities
1803 // FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1804 // if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1805 // // update priority for feature
1806 // updateSelectionPriority(aFeature, aFeature);
1807 // // update priority for results of the feature
1808 // std::list<ResultPtr> aResults = aFeature->results();
1809 // std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1810 // for (; anIt != aLastIt; anIt++)
1811 // updateSelectionPriority(*anIt, aFeature);
1815 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1817 return myModule->workshop()->currentOperation();
1820 //**************************************************************
1821 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1823 ModuleBase_ModelWidget* aWidget = 0;
1824 ModuleBase_Operation* anOperation = getCurrentOperation();
1826 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1828 aWidget = aPanel->activeWidget();
1833 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1834 const bool isEditOperation,
1835 const bool isToDisplay,
1836 const bool isFlushRedisplay)
1838 #ifdef DEBUG_DO_NOT_BY_ENTER
1842 if (isEditOperation || !theFeature.get())
1845 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1846 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1848 // 1. change visibility of the object itself, here the presentable object is processed,
1849 // e.g. constraints features
1850 //FeaturePtr aFeature = aFOperation->feature();
1851 std::list<ResultPtr> aResults = theFeature->results();
1853 theFeature->setDisplayed(true);
1855 theFeature->setDisplayed(false);
1857 // change visibility of the object results, e.g. non-constraint features
1858 std::list<ResultPtr>::const_iterator aIt;
1859 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1861 (*aIt)->setDisplayed(true);
1864 (*aIt)->setDisplayed(false);
1867 if (isFlushRedisplay)
1868 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1871 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1872 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1874 if (!myCurrentSketch.get())
1877 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1878 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1879 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1881 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1882 aStoredPrs = aSelect->getHighlighted();
1884 QList<FeaturePtr> aFeatureList;
1885 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1886 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1887 ModuleBase_ISelection::AllControls);
1888 aStoredPrs.append(aSelected);
1891 // 1. it is necessary to save current selection in order to restore it after the features moving
1892 theCurrentSelection.clear();
1894 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1895 aLast = aStoredPrs.end();
1897 CompositeFeaturePtr aSketch = activeSketch();
1898 for (; anIt != aLast; anIt++) {
1899 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1900 ObjectPtr anObject = aPrs->object();
1901 if (!anObject.get())
1904 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1905 FeaturePtr aFeature;
1907 aFeature = ModelAPI_Feature::feature(aResult);
1909 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1911 if (!aFeature.get())
1914 std::set<AttributePtr> aSelectedAttributes;
1915 std::set<ResultPtr> aSelectedResults;
1916 SelectionInfo anInfo;
1917 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1918 anInfo = theCurrentSelection.find(aFeature).value();
1920 TopoDS_Shape aFirstShape;
1921 ResultPtr aFirstResult = aFeature->firstResult();
1922 if (aFirstResult.get() && aFirstResult->shape().get())
1923 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1924 anInfo.myFirstResultShape = aFirstShape;
1925 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1926 if (aResult.get()) {
1927 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1928 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1931 std::list<ResultPtr> aResults = aFeature->results();
1932 std::list<ResultPtr>::const_iterator aIt;
1933 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1934 ResultPtr aResult = *aIt;
1935 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1936 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1939 theCurrentSelection[aFeature] = anInfo;
1941 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1944 void PartSet_SketcherMgr::restoreSelection(
1945 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1947 if (!myCurrentSketch.get())
1950 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1951 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1952 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1953 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
1954 aSLast = theCurrentSelection.end();
1955 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1956 anOwnersToSelect.Clear();
1957 for (; aSIt != aSLast; aSIt++) {
1958 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
1961 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1964 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1966 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1968 updateBySketchParameters(aType, theState);
1969 myModule->workshop()->viewer()->update();
1972 void PartSet_SketcherMgr::updateBySketchParameters(
1973 const PartSet_Tools::ConstraintVisibleState& theType,
1976 if (myCurrentSketch.get() == NULL)
1979 bool aPrevState = myIsConstraintsShown[theType];
1980 myIsConstraintsShown[theType] = theState;
1983 case PartSet_Tools::Geometrical:
1984 case PartSet_Tools::Dimensional: {
1985 if (aPrevState != theState) {
1986 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1987 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1988 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1989 for (int i = 0; i < aNumberOfSubs; i++) {
1990 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1991 bool aProcessed = false;
1992 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1994 aSubFeature->setDisplayed(aConstraintDisplayed);
1996 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2000 case PartSet_Tools::Expressions: {
2001 if (aPrevState != theState) {
2002 /// call all sketch features redisplay, the expression state will be corrected in customize
2003 /// of distance presentation
2004 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2005 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
2012 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
2013 FeaturePtr theFeature)
2015 if (!theObject.get() || !theFeature.get())
2018 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
2019 Handle(AIS_InteractiveObject) anAISIO;
2020 if (anAIS.get() != NULL) {
2021 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
2024 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
2025 int anAdditionalPriority = 0;
2027 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2028 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
2029 if (aSPFeature.get() != NULL) {
2031 // 2. Simple segments
2032 // 3. External objects (violet color)
2033 // 4. Auxiliary segments (dotted)
2034 // StdSelect_BRepSelectionTool::Load uses priority calculating:
2035 // Standard_Integer aPriority =
2036 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
2037 // Priority of Vertex is 8, edge(segment) is 7.
2038 // It might be not corrected as provides the condition above.
2039 bool isExternal = aSPFeature->isExternal();
2040 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
2042 if (!isExternal && !isAuxiliary)
2043 anAdditionalPriority = 30;
2046 anAdditionalPriority = 20;
2047 // auxiliary feature
2049 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
2050 // edges/vertices of local selection on not-sketch objects
2052 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
2053 if (!aResult.IsNull()) {
2054 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
2060 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
2062 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
2063 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
2064 return aConnector->workshop();
2067 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
2069 return workshop()->operationMgr();
2072 void PartSet_SketcherMgr::onShowPoints(bool toShow)
2074 if (!myCurrentSketch.get())
2076 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2077 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
2078 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
2080 bool aToUpdate = false;
2082 std::list<ResultPtr> aFreePoints = SketcherPrs_Tools::getFreePoints(myCurrentSketch);
2084 // Delete obsolete presentations
2085 std::list<ResultPtr> aDelList;
2086 foreach(ResultPtr aObj, myPointsHighlight.keys()) {
2087 bool aFound = (std::find(aFreePoints.begin(), aFreePoints.end(), aObj) != aFreePoints.end());
2089 aDelList.push_back(aObj);
2091 foreach(ResultPtr aObj, aDelList) {
2092 aContext->Remove(myPointsHighlight[aObj], false);
2094 myPointsHighlight.remove(aObj);
2097 // Display new objects
2098 QList<ResultPtr> aKeysList = myPointsHighlight.keys();
2099 std::list<ResultPtr>::const_iterator aIt;
2100 for (aIt = aFreePoints.cbegin(); aIt != aFreePoints.cend(); aIt++) {
2101 if (!aKeysList.contains(*aIt)) {
2102 GeomShapePtr aShapePtr = (*aIt)->shape();
2103 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
2104 Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape);
2105 aShapePrs->SetColor(Quantity_NOC_BLUE1);
2106 aShapePrs->SetZLayer(Graphic3d_ZLayerId_Top);
2107 Handle(Prs3d_Drawer) aDrawer = aShapePrs->Attributes();
2108 if (aDrawer->HasOwnPointAspect()) {
2109 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
2110 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
2111 aDrawer->PointAspect()->SetScale(2);
2114 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2));
2115 aContext->Display(aShapePrs, false);
2116 aContext->Deactivate(aShapePrs);
2117 myPointsHighlight[*aIt] = aShapePrs;
2123 foreach(Handle(AIS_Shape) aPrs, myPointsHighlight.values()) {
2124 aContext->Remove(aPrs, false);
2127 myPointsHighlight.clear();
2133 void PartSet_SketcherMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
2135 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOF_OBJECTS)) {
2136 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
2137 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
2138 std::set<ObjectPtr> aObjects = anUpdateMsg->objects();
2139 std::set<ObjectPtr>::const_iterator aIt;
2140 QList<ModuleBase_ViewerPrsPtr> aPrsList;
2141 for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
2142 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aIt);
2143 if (aFeature.get()) {
2144 std::list<ResultPtr> aRes = aFeature->results();
2145 std::list<ResultPtr>::const_iterator aIt;
2146 for (aIt = aRes.cbegin(); aIt != aRes.cend(); ++aIt) {
2147 ModuleBase_ViewerPrsPtr aPrsPtr(new ModuleBase_ViewerPrs(*aIt));
2148 aPrsList.append(aPrsPtr);
2152 if (aPrsList.size() > 0) {
2153 myModule->workshop()->setSelected(aPrsList);
2158 bool isExternal(const ObjectPtr& theObject)
2160 AttributeSelectionPtr aAttr =
2161 theObject->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
2163 return aAttr->context().get() != NULL && !aAttr->isInvalid();
2167 bool isCopy(const ObjectPtr& theObject)
2169 AttributeBooleanPtr anAttr = theObject->data()->boolean(SketchPlugin_SketchEntity::COPY_ID());
2171 return anAttr->value();
2175 bool isIncludeToResult(const ObjectPtr& theObject)
2177 AttributeBooleanPtr anAttr;
2178 std::set<AttributePtr> aRefsToMe = theObject->data()->refsToMe();
2179 std::set<AttributePtr>::const_iterator aIt;
2180 for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) {
2181 if ((*aIt)->id() == SketchPlugin_Projection::PROJECTED_FEATURE_ID()) {
2182 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aIt)->owner());
2183 if (aFeature.get()) {
2184 anAttr = aFeature->data()->boolean(SketchPlugin_Projection::INCLUDE_INTO_RESULT());
2186 return anAttr->value();
2193 //**************************************************************************************
2194 std::vector<int> PartSet_SketcherMgr::colorOfObject(const ObjectPtr& theObject,
2195 const FeaturePtr& theFeature, bool isConstruction) const
2197 static const QStringList& aConstrIds = constraintsIdList();
2198 PartSet_OverconstraintListener* aOCListener = myModule->overconstraintListener();
2199 std::string aKind = theFeature->getKind();
2201 if (isDistanceKind(aKind)) {
2202 if (aOCListener->isConflictingObject(theObject))
2203 return Config_PropManager::color("Visualization", "sketch_overconstraint_color");
2204 return Config_PropManager::color("Visualization", "sketch_dimension_color");
2206 if (isExternal(theFeature))
2207 return Config_PropManager::color("Visualization", "sketch_external_color");
2209 return Config_PropManager::color("Visualization", "sketch_auxiliary_color");
2211 if (aOCListener->isFullyConstrained()) {
2212 return Config_PropManager::color("Visualization", "sketch_fully_constrained_color");
2214 else if (aOCListener->isConflictingObject(theObject)) {
2215 return Config_PropManager::color("Visualization", "sketch_overconstraint_color");
2217 return Config_PropManager::color("Visualization", "sketch_entity_color");
2220 //**************************************************************************************
2221 void PartSet_SketcherMgr::customizeSketchPresentation(const ObjectPtr& theObject,
2222 const AISObjectPtr& thePrs) const
2224 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
2226 // set color from preferences
2227 std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
2228 aFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
2229 bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
2231 std::vector<int> aColor = colorOfObject(theObject, aFeature, isConstruction);
2232 if (!aColor.empty()) {
2233 // The code below causes redisplay again
2234 if (ModelAPI_Session::get()->isOperation()) {
2235 AttributeIntArrayPtr aColorAttr = theObject->data()->intArray(ModelAPI_Result::COLOR_ID());
2236 if (aColorAttr.get()) {
2237 aColorAttr->setSize(3, false);
2238 // Set the color attribute in order do not use default colors in the presentation object
2239 for (int i = 0; i < 3; i++)
2240 aColorAttr->setValue(i, aColor[i], false);
2243 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
2246 int aShapeType = thePrs->getShapeType();
2247 // a compound is processed like the edge because the
2248 // arc feature uses the compound for presentable AIS
2249 if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
2252 if (isExternal(aFeature)) {
2253 thePrs->setWidth(1);
2256 std::string aKind = aFeature->getKind();
2257 if (isDistanceKind(aKind))
2260 if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
2261 if (isConstruction) {
2262 // Set axilliary line
2263 thePrs->setWidth(SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY());
2264 thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY());
2267 int aWidth = Config_PropManager::integer("Visualization", "sketch_line_width");
2268 thePrs->setWidth(aWidth);
2269 thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE());
2272 else if (aShapeType == 7) { // otherwise this is a vertex
2273 // The width value do not have effect on the point presentation.
2274 // It is defined in order to extend selection area of the object.
2275 thePrs->setWidth(17);
2276 // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
2278 if (isCopy(aFeature) && !isIncludeToResult(aFeature)) {
2279 double aWidth = thePrs->width();
2280 thePrs->setWidth(aWidth / 2.5);
2283 double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
2284 thePrs->setDeflection(aDeflection);
2287 //*************************************************************************************
2288 void PartSet_Fitter::fitAll(Handle(V3d_View) theView)
2290 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
2292 ModuleBase_IWorkshop* aWorkshop = mySketchMgr->module()->workshop();
2293 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
2294 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
2297 int aNumberOfSubs = aSketch->numberOfSubs();
2298 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2299 for (int i = 0; i < aNumberOfSubs; i++) {
2300 FeaturePtr aFeature = aSketch->subFeature(i);
2301 if (aDisplayer->isVisible(aFeature)) {
2302 AISObjectPtr aAisPtr = aDisplayer->getAISObject(aFeature);
2303 Handle(AIS_InteractiveObject) aAisObj = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2304 if (!aAisObj->IsInfinite()) {
2306 aAisObj->BoundingBox(aBox);
2311 std::list<ResultPtr> aResults = aFeature->results();
2312 std::list<ResultPtr>::const_iterator aIt;
2314 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
2316 if (aRes->isDisplayed()) {
2317 FeaturePtr aFeature = ModelAPI_Feature::feature(aRes);
2318 if (aFeature.get()) {
2319 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2320 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
2321 if (aSPFeature.get()) {
2323 aSPFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
2324 if (!(aSPFeature->isExternal() || isAxiliary)) {
2325 GeomShapePtr aShape = aRes->shape();
2326 aShape->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2328 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2337 if (aBndBox.IsVoid())
2340 theView->FitAll(aBndBox, 0.01);