1 // Copyright (C) 2014-2021 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>
63 #include <GeomDataAPI_Point2DArray.h>
65 #include <GeomAPI_Shape.h>
67 #include <Events_Loop.h>
69 #include <SketchPlugin_Line.h>
70 #include <SketchPlugin_Sketch.h>
71 #include <SketchPlugin_Point.h>
72 #include <SketchPlugin_Arc.h>
73 #include <SketchPlugin_Circle.h>
74 #include <SketchPlugin_Ellipse.h>
75 #include <SketchPlugin_EllipticArc.h>
76 #include <SketchPlugin_ConstraintLength.h>
77 #include <SketchPlugin_ConstraintDistance.h>
78 #include <SketchPlugin_ConstraintParallel.h>
79 #include <SketchPlugin_ConstraintPerpendicular.h>
80 #include <SketchPlugin_ConstraintRadius.h>
81 #include <SketchPlugin_ConstraintRigid.h>
82 #include <SketchPlugin_ConstraintHorizontal.h>
83 #include <SketchPlugin_ConstraintVertical.h>
84 #include <SketchPlugin_ConstraintEqual.h>
85 #include <SketchPlugin_ConstraintTangent.h>
86 #include <SketchPlugin_ConstraintCoincidence.h>
87 #include <SketchPlugin_Fillet.h>
88 #include <SketchPlugin_ConstraintMirror.h>
89 #include <SketchPlugin_ConstraintAngle.h>
90 #include <SketchPlugin_ConstraintCollinear.h>
91 #include <SketchPlugin_ConstraintMiddle.h>
92 #include <SketchPlugin_MultiRotation.h>
93 #include <SketchPlugin_MultiTranslation.h>
94 #include <SketchPlugin_IntersectionPoint.h>
95 #include <SketchPlugin_Projection.h>
96 #include <SketchPlugin_ConstraintDistanceAlongDir.h>
97 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
98 #include <SketchPlugin_ConstraintDistanceVertical.h>
100 #include <SketcherPrs_Tools.h>
102 #include <SelectMgr_IndexedMapOfOwner.hxx>
103 #include <StdSelect_BRepOwner.hxx>
105 //#include <AIS_DimensionSelectionMode.hxx>
106 #include <AIS_Shape.hxx>
107 #include <AIS_Dimension.hxx>
109 #include <ModelAPI_Events.h>
110 #include <ModelAPI_Session.h>
111 #include <ModelAPI_AttributeString.h>
113 #include <ModelAPI_Validator.h>
114 #include <ModelAPI_Tools.h>
116 #include <QMouseEvent>
117 #include <QApplication>
119 #include <QMessageBox>
120 #include <QMainWindow>
124 //#define DEBUG_DO_NOT_BY_ENTER
125 //#define DEBUG_SKETCHER_ENTITIES
126 //#define DEBUG_SKETCH_ENTITIES_ON_MOVE
127 //#define DRAGGING_DEBUG
128 //#define DEBUG_CURSOR
131 #ifdef DRAGGING_DEBUG
135 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
136 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge,
137 /// put the function result as is to the list of results.
138 /// \param theOwner a viewer selected owner
139 /// \param theFeature a feature, where the attribute is searched
140 /// \param theSketch a current sketch
141 /// \param theSelectedAttribute an output list of attributes
142 /// \param theSelectedResults an output list of edge results
143 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
144 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
145 const ResultPtr& theResult,
146 std::map<AttributePtr, int>& theSelectedAttributes,
147 std::set<ResultPtr>& theSelectedResults,
148 TopTools_MapOfShape& theShapes)
150 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
151 if (aBRepOwner.IsNull())
153 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
154 aBRepOwner->Selectable());
155 if (aBRepOwner->HasShape()) {
156 const TopoDS_Shape& aShape = aBRepOwner->Shape();
157 theShapes.Add(aShape);
158 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
159 if (aShapeType == TopAbs_VERTEX) {
160 std::pair<AttributePtr, int> aPntAttrIndex =
161 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
162 if (aPntAttrIndex.first.get() != NULL)
163 theSelectedAttributes[aPntAttrIndex.first] = aPntAttrIndex.second;
165 else if (aShapeType == TopAbs_EDGE &&
166 theSelectedResults.find(theResult) == theSelectedResults.end()) {
167 theSelectedResults.insert(theResult);
172 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
173 : QObject(theModule),
175 myIsEditLaunching(false),
178 myIsMouseOverWindow(false),
179 myIsMouseOverViewProcessed(true),
180 myIsPopupMenuActive(false),
181 myPreviousUpdateViewerEnabled(true),
182 myExternalPointsMgr(0),
183 myNoDragMoving(false)
185 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
186 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
188 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
190 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
191 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
193 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
194 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
196 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
197 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
199 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
200 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
202 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
203 XGUI_Workshop* aWorkshop = aConnector->workshop();
204 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
206 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
207 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
208 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
210 mySketchPlane = new PartSet_PreviewSketchPlane();
212 registerSelectionFilter(SF_SketchCirclePointFilter, new PartSet_CirclePointFilter(anIWorkshop));
213 registerSelectionFilter(SF_SketchPlaneFilter, new ModuleBase_ShapeInPlaneFilter());
215 Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_DOF_OBJECTS));
218 PartSet_SketcherMgr::~PartSet_SketcherMgr()
220 delete mySketchPlane;
223 void PartSet_SketcherMgr::onEnterViewPort()
225 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
226 // created feature because it should be done in onMouseMove(). Some widgets watch
227 // the mouse move and use the cursor position to update own values. If the presentaion is
228 // redisplayed before this update, the feature presentation jumps from reset value to current.
229 myIsMouseOverWindow = true;
231 #ifdef DEBUG_DO_NOT_BY_ENTER
235 // It is switched off because of
236 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
237 if (canChangeCursor(getCurrentOperation())) {
238 QCursor* aCurrentCursor = QApplication::overrideCursor();
239 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
240 QApplication::setOverrideCursor(PartSet_Tools::getOperationCursor());
241 //#ifdef DEBUG_CURSOR
242 // qDebug("onEnterViewPort() : Qt::CrossCursor");
247 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
250 operationMgr()->onValidateOperation();
252 // we need change displayed state of the current operation feature
253 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
254 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
255 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
256 // presentation becomes valid and redisplay happens
257 //ModuleBase_Operation* aOperation = getCurrentOperation();
258 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
259 (getCurrentOperation());
261 FeaturePtr aFeature = aFOperation->feature();
262 if (aFeature.get() && aFeature->data()->isValid()) {
263 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
268 void PartSet_SketcherMgr::onLeaveViewPort()
270 myIsMouseOverViewProcessed = false;
271 myIsMouseOverWindow = false;
273 #ifdef DEBUG_DO_NOT_BY_ENTER
277 if (canChangeCursor(getCurrentOperation())) {
278 QApplication::restoreOverrideCursor();
279 //#ifdef DEBUG_CURSOR
280 // qDebug("onLeaveViewPort() : None");
284 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
287 // the method should be performed if the popup menu is called,
288 // the reset of the current widget should not happen
289 if (myIsPopupMenuActive)
292 // it is important to validate operation here only if sketch entity create operation is active
293 // because at this operation we reacts to the mouse leave/enter view port
294 operationMgr()->onValidateOperation();
296 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
297 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
298 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
299 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
300 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
301 // obtained after reset value
302 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
303 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
305 anActiveWidget->reset();
307 // hides the presentation of the current operation feature
308 // the feature is to be erased here, but it is correct to call canDisplayObject because
309 // there can be additional check (e.g. editor widget in distance constraint)
310 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
311 (getCurrentOperation());
313 FeaturePtr aFeature = aFOperation->feature();
314 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
316 // we should update viewer after the presentation are hidden in the viewer
317 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
318 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
322 //Temporary commented as we do not modify values in property panel
323 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
325 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
326 myModule->sketchReentranceMgr()->isInternalEditActive())
328 // it is necessary to save current selection in order to restore it after the values are modifed
329 storeSelection(ST_SelectAndHighlightType);
331 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
332 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
333 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
334 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
337 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
339 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
340 myModule->sketchReentranceMgr()->isInternalEditActive()) {
341 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
344 // it is necessary to restore current selection in order to restore it after values are modified
346 myCurrentSelection.clear();
348 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
349 // viewer happens by deselect/select the modified objects. The flag should be restored after
350 // the selection processing. The update viewer should be also called.
351 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
352 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
353 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
354 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
355 aDisplayer->updateViewer();
359 bool PartSet_SketcherMgr::isDragModeCreation() const
361 ModuleBase_Operation* aOp = getCurrentOperation();
364 bool aUserPref = Config_PropManager::boolean(SKETCH_TAB_NAME, "create_by_dragging");
367 QString aId = aOp->id();
368 // Acceptable features;
370 aList << "SketchLine" << "SketchMacroCircle" << "SketchMacroArc" <<
371 "SketchMacroEllipse" << "SketchMacroEllipticArc" << "SketchMacroRectangle";
372 return aList.contains(aId);
375 static bool MyModeByDrag = false;
376 static bool MyMultiselectionState = true;
378 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
380 MyModeByDrag = isDragModeCreation();
382 // Clear dragging mode
383 myIsDragging = false;
385 myMousePoint.setX(theEvent->x());
386 myMousePoint.setY(theEvent->y());
388 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
390 //get2dPoint(theWnd, theEvent, myClickedPoint);
391 if (!(theEvent->buttons() & Qt::LeftButton))
394 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
395 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
396 //if (!aViewer->canDragByMouse())
399 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
400 (getCurrentOperation());
404 bool isEditing = aFOperation->isEditOperation();
405 bool aCanDrag = aViewer->canDragByMouse();
407 //if (!aViewer->canDragByMouse() && isEditing) {
408 // // Do not edit by dragging
413 // If the current widget is a selector, do nothing, it processes the mouse press
414 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
415 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
420 // Use only for sketch operations
421 if (myCurrentSketch) {
422 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
425 bool isSketcher = isSketchOperation(aFOperation);
426 bool isSketchOpe = isNestedSketchOperation(aFOperation);
428 // Avoid non-sketch operations
429 if ((!isSketchOpe) && (!isSketcher))
432 // Ignore creation sketch operation
433 if ((!isSketcher) && (!isEditing)) {
435 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
436 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
438 MyMultiselectionState = aViewer->isMultiSelectionEnabled();
439 aViewer->enableMultiselection(false);
441 ModuleBase_ISelection* aSelection = aWorkshop->selection();
442 QList<ModuleBase_ViewerPrsPtr> aPreSelected = aSelection->getHighlighted();
443 if (!aPreSelected.empty())
444 aProcessor->setPreSelection(aPreSelected.first(), theWnd, theEvent);
446 aProcessor->mouseReleased(theWnd, theEvent);
451 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
452 storeSelection(aHasShift ? ST_SelectAndHighlightType : ST_HighlightType, myCurrentSelection);
454 if (myCurrentSelection.empty()) {
455 if (isSketchOpe && (!isSketcher))
456 // commit previous operation
457 if (!aFOperation->commit())
458 aFOperation->abort();
461 // Init flyout point for radius rotation
462 FeaturePtr aFeature = myCurrentSelection.begin().key();
463 get2dPoint(theWnd, theEvent, myCurrentPoint);
469 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
471 } else if (isSketchOpe && isEditing) {
472 // If selected another object commit current result
473 bool aPrevLaunchingState = myIsEditLaunching;
474 /// store editing state for Edit operation in order to do not clear highlight by restart
475 /// of edit operation.
476 /// Internal edit should not be stored as editing operation as the result will be a
477 /// creation operation, where previous selection should not be used(and will be cleared)
478 myIsEditLaunching = !myModule->sketchReentranceMgr()->isInternalEditActive();
480 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
481 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFOperation->feature());
482 bool isRelaunchEditing = true;
483 if (aSPFeature->isExternal()) {
484 foreach(FeaturePtr aF, myCurrentSelection.keys()) {
485 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aF,
486 aSPFeature->getKind());
487 if (aProducerFeature == aSPFeature) {
488 isRelaunchEditing = false;
494 if (myCurrentSelection.size() > 1)
495 isRelaunchEditing = !myCurrentSelection.contains(aSPFeature);
497 if (isRelaunchEditing)
498 aFOperation->commit();
504 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
505 if (isRelaunchEditing)
508 if (myCurrentSelection.size() > 1)
509 aFOperation->propertyPanel()->cleanContent();
511 myIsEditLaunching = aPrevLaunchingState;
512 if (aFeature.get() != NULL) {
513 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
514 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
515 if (aSketchFeature.get() &&
516 (aSketchFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
517 aSketchFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
518 DataPtr aData = aSketchFeature->data();
519 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
520 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
521 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
522 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
529 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
531 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
532 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
534 aViewer->enableDrawMode(myPreviousDrawModeEnabled);
536 bool aWasDragging = myIsDragging;
537 myIsDragging = false;
539 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent)) {
542 // if mouse is pressed when it was over view and at release the mouse is out of view, do nothing
543 if (!myIsMouseOverViewProcessed) {
547 ModuleBase_OperationFeature* aOp =
548 dynamic_cast<ModuleBase_OperationFeature*>(getCurrentOperation());
549 bool isEditing = false;
551 isEditing = aOp->isEditOperation();
552 bool aStartNoDragOperation = !aViewer->canDragByMouse() && isEditing;
553 if (aStartNoDragOperation || myNoDragMoving) {
554 // Process edit operation without dragging
555 if (myCurrentSelection.size() > 0)
556 myNoDragMoving = !myNoDragMoving;
558 myNoDragMoving = false;
562 restoreSelection(myCurrentSelection);
563 myCurrentSelection.clear();
567 if (isNestedSketchOperation(aOp)) {
568 // Only for sketcher operations
571 /// the previous selection is lost by mouse release in the viewer(Select method), but
572 /// it is still stored in myCurrentSelection. So, it is possible to restore selection
573 /// It is important for drag(edit with mouse) of sketch entities.
574 restoreSelection(myCurrentSelection);
575 myCurrentSelection.clear();
582 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
583 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
585 ModuleBase_ISelection* aSelection = aWorkshop->selection();
586 QList<ModuleBase_ViewerPrsPtr> aPreSelected = aSelection->getHighlighted();
587 if (MyModeByDrag && !aPreSelected.empty() && !isEditing)
588 aProcessor->setPreSelection(aPreSelected.first(), theWnd, theEvent);
590 aProcessor->mouseReleased(theWnd, theEvent);
592 if (MyModeByDrag && aOp) {
593 aViewer->enableMultiselection(true);
594 QString aOpId = aOp->id();
595 if (aOpId == "Sketch")
597 QPoint aPnt(theEvent->x(), theEvent->y());
598 anActiveWidget = getActiveWidget();
599 if ((aPnt == myMousePoint) && anActiveWidget) {
603 bool aCanRestart = !anActiveWidget && !isEditing;
605 module()->launchOperation(aOpId, true);
610 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
612 #ifdef DEBUG_SKETCH_ENTITIES_ON_MOVE
613 CompositeFeaturePtr aSketch = activeSketch();
615 std::cout << "mouse move SKETCH FEATURES [" << aSketch->numberOfSubs() << "]:" << std::endl;
617 for (int i = 0, aNbSubs = aSketch->numberOfSubs(); i < aNbSubs; i++) {
618 //std::cout << getFeatureInfo(aSketch->subFeature(i), false) << std::endl;
619 anInfo.append(ModuleBase_Tools::objectInfo(aSketch->subFeature(i)));
621 QString anInfoStr = anInfo.join("\n");
622 qDebug(QString("%1").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
626 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
629 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
630 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
631 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
633 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
634 #ifdef DRAGGING_DEBUG
638 // 1. perform the widget mouse move functionality and display the presentation
639 // the mouse move should be processed in the widget, if it can in order to visualize correct
640 // presentation. These widgets correct the feature attribute according to the mouse position
641 ModuleBase_ModelWidget* anActiveWidget = myModule->activeWidget();
642 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
644 aProcessor->mouseMoved(theWnd, theEvent);
645 if (!myIsMouseOverViewProcessed) {
646 myIsMouseOverViewProcessed = true;
648 // the feature is to be erased here, but it is correct to call canDisplayObject because
649 // there can be additional check (e.g. editor widget in distance constraint)
650 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
651 (getCurrentOperation());
653 FeaturePtr aFeature = aFOperation->feature();
654 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
657 aDisplayer->updateViewer();
658 #ifdef DRAGGING_DEBUG
659 cout << "Mouse move processing " << t.elapsed() << endl;
662 //myClickedPoint.clear();
664 if (myIsDragging || myNoDragMoving) {
665 // 1. the current selection is saved in the mouse press method in order to restore it after
667 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
668 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
669 // deselected). This flag should be restored in the slot, processed the mouse release signal.
670 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
671 if (!aCurrentOperation)
673 if (isSketchOperation(aCurrentOperation))
674 return; // No edit operation activated
676 #ifdef DRAGGING_DEBUG
681 Handle(V3d_View) aView = theWnd->v3dView();
683 get2dPoint(theWnd, theEvent, aMousePnt);
685 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
686 new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
687 std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
688 new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
690 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
691 // viewer happens by deselect/select the modified objects. The flag should be restored after
692 // the selection processing. The update viewer should be also called.
693 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
695 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
696 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
697 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
698 aLast = myCurrentSelection.end();
699 // 4. the features and attributes modification(move)
700 bool isModified = false;
701 for (; anIt != aLast; anIt++) {
702 FeaturePtr aFeature = anIt.key();
704 std::map<AttributePtr, int> anAttributes = anIt.value().myAttributes;
705 // Process selection by attribute: the priority to the attribute
706 if (!anAttributes.empty()) {
707 std::map<AttributePtr, int>::const_iterator anAttIt = anAttributes.begin(),
708 anAttLast = anAttributes.end();
709 for (; anAttIt != anAttLast; anAttIt++) {
710 AttributePtr anAttr = anAttIt->first;
711 if (anAttr.get() == NULL)
713 std::string aAttrId = anAttr->id();
714 DataPtr aData = aFeature->data();
715 if (aData->isValid()) {
716 AttributePtr aPoint = aData->attribute(aAttrId);
717 if (aPoint->attributeType() == GeomDataAPI_Point2D::typeId() ||
718 aPoint->attributeType() == GeomDataAPI_Point2DArray::typeId()) {
719 bool isImmutable = aPoint->setImmutable(true);
721 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
722 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
723 aMessage->setMovedAttribute(aPoint, anAttIt->second);
724 aMessage->setOriginalPosition(anOriginalPosition);
725 aMessage->setCurrentPosition(aCurrentPosition);
726 Events_Loop::loop()->send(aMessage);
729 aPoint->setImmutable(isImmutable);
735 // Process selection by feature
736 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
737 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
738 if (aSketchFeature) {
739 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
740 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
741 aMessage->setMovedObject(aFeature);
742 aMessage->setOriginalPosition(anOriginalPosition);
743 aMessage->setCurrentPosition(aCurrentPosition);
744 Events_Loop::loop()->send(aMessage);
749 // the modified state of the current operation should be updated if there are features, which
752 aCurrentOperation->onValuesChanged();
753 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
755 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
757 // 5. it is necessary to save current selection in order to restore it after the features moving
758 restoreSelection(myCurrentSelection);
759 // 6. restore the update viewer flag and call this update
760 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
761 aDisplayer->updateViewer();
763 #ifdef DRAGGING_DEBUG
764 cout << "Mouse move processing " << t.elapsed() << endl;
768 myCurrentPoint = aMousePnt;
772 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
774 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
775 (getCurrentOperation());
776 if (aFOperation && aFOperation->isEditOperation()) {
777 std::string aId = aFOperation->id().toStdString();
778 if (isDistanceOperation(aFOperation))
780 // Activate dimension value editing on double click
781 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
782 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
783 // Find corresponded widget to activate value editing
784 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
785 std::string anId = aWgt->attributeID();
786 if (anId == SketchPlugin_Constraint::VALUE() ||
787 anId == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() ||
788 anId == SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()) {
789 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
791 anEditor->showPopupEditor();
799 void PartSet_SketcherMgr::onApplicationStarted()
801 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
802 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
803 XGUI_Workshop* aWorkshop = aConnector->workshop();
804 PartSet_SketcherReentrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
806 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
807 if (aPropertyPanel) {
808 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
809 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
811 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
812 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
813 //connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
814 // aReentranceMgr, SLOT(onWidgetActivated()));
817 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
818 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
819 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
821 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
822 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
823 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
826 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
828 //if (!myClickedPoint.myIsInitialized)
831 //ModuleBase_Operation* aOperation = getCurrentOperation();
832 // the distance constraint feature should not use the clickedd point
833 // this is workaround in order to don't throw down the flyout point value,
834 // set by execute() method of these type of features
835 //if (isDistanceOperation(aOperation))
838 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
840 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
844 void PartSet_SketcherMgr::onBeforeContextMenu()
846 myIsPopupMenuActive = true;
849 void PartSet_SketcherMgr::onAfterContextMenu()
851 myIsPopupMenuActive = false;
854 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
857 Handle(V3d_View) aView = theWnd->v3dView();
858 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
860 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
861 thePoint.setValue(aX, anY);
864 void PartSet_SketcherMgr::launchEditing()
866 if (!myCurrentSelection.empty()) {
867 FeaturePtr aFeature = myCurrentSelection.begin().key();
868 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
869 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
871 if (!aSPFeature->isExternal())
872 myModule->editFeature(aSPFeature);
874 // need to edit a feature (Projection/IntersectionPoint),
875 // which produces current External feature
876 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
877 SketchPlugin_Projection::ID());
878 if (!aProducerFeature.get())
879 aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
880 SketchPlugin_IntersectionPoint::ID());
881 if (aProducerFeature.get())
882 myModule->editFeature(aProducerFeature);
888 bool PartSet_SketcherMgr::sketchSolverError()
890 bool anError = false;
891 CompositeFeaturePtr aSketch = activeSketch();
893 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
894 anError = !aAttributeString->value().empty();
899 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
902 if (!theFeature.get() || !theFeature->data()->isValid())
905 CompositeFeaturePtr aSketch = activeSketch();
906 if (aSketch.get() && aSketch == theFeature) {
907 std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
908 anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
913 void PartSet_SketcherMgr::clearClickedFlags()
915 //myClickedPoint.clear();
916 myCurrentPoint.clear();
919 const QStringList& PartSet_SketcherMgr::replicationsIdList()
921 static QStringList aReplicationIds;
922 if (aReplicationIds.size() == 0) {
923 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
924 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
925 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
927 return aReplicationIds;
930 const QStringList& PartSet_SketcherMgr::constraintsIdList()
932 static QStringList aConstraintIds;
933 if (aConstraintIds.size() == 0) {
934 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
935 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
936 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
937 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
938 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
939 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
940 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
941 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
942 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
943 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
944 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
945 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
946 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
947 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
948 aConstraintIds << SketchPlugin_ConstraintMirror::ID().c_str();
949 aConstraintIds << SketchPlugin_MultiTranslation::ID().c_str();
950 aConstraintIds << SketchPlugin_MultiRotation::ID().c_str();
951 aConstraintIds << SketchPlugin_ConstraintDistanceAlongDir::ID().c_str();
952 aConstraintIds << SketchPlugin_ConstraintDistanceHorizontal::ID().c_str();
953 aConstraintIds << SketchPlugin_ConstraintDistanceVertical::ID().c_str();
955 return aConstraintIds;
958 void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSketch,
961 if (!theSketch.get() || !PartSet_Tools::sketchPlane(theSketch).get())
964 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
965 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
966 theModes.append(SketcherPrs_Tools::Sel_Constraint);
967 theModes.append(TopAbs_VERTEX);
968 theModes.append(TopAbs_EDGE);
971 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ObjectPtr& theObj)
973 Handle(AIS_InteractiveObject) aPrs;
975 FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
976 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
977 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
979 aPrs = new PartSet_ResultSketchPrs(aResult);
984 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
986 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
989 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
991 bool aNestedSketch = false;
993 FeaturePtr anActiveSketch = activeSketch();
994 if (anActiveSketch.get() && theOperation) {
995 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
996 anActiveSketch->getKind().c_str());
997 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
999 if (aSketchOperation && aFOperation) {
1000 FeaturePtr aFeature = aFOperation->feature();
1001 if (aFeature.get()) {
1002 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
1003 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
1007 return aNestedSketch;
1010 bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const
1012 bool aNestedSketch = false;
1014 FeaturePtr anActiveSketch = activeSketch();
1015 if (anActiveSketch.get()) {
1016 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
1017 anActiveSketch->getKind().c_str());
1018 if (aSketchOperation) {
1019 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
1020 aNestedSketch = aGrantedOpIds.contains(theFeatureKind);
1023 return aNestedSketch;
1026 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
1027 const CompositeFeaturePtr& theSketch) const
1029 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1031 return aFOperation && !aFOperation->isEditOperation() &&
1032 isNestedSketchOperation(aFOperation);
1035 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
1036 const CompositeFeaturePtr& theSketch) const
1038 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1040 return aFOperation && aFOperation->isEditOperation() &&
1041 isNestedSketchOperation(aFOperation);
1044 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
1046 return (theId == SketchPlugin_Line::ID()) ||
1047 (theId == SketchPlugin_Point::ID()) ||
1048 (theId == SketchPlugin_Arc::ID()) ||
1049 (theId == SketchPlugin_Circle::ID()) ||
1050 (theId == SketchPlugin_Ellipse::ID()) ||
1051 (theId == SketchPlugin_Projection::ID()) ||
1052 (theId == SketchPlugin_IntersectionPoint::ID()) ||
1053 (theId == SketchPlugin_EllipticArc::ID());
1056 bool PartSet_SketcherMgr::isExternalFeature(const FeaturePtr& theFeature)
1058 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
1059 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
1060 return aSPFeature.get() && aSPFeature->isExternal();
1063 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
1065 std::string anId = theOperation ? theOperation->id().toStdString() : "";
1067 return isDistanceKind(anId);
1070 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
1072 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
1073 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
1074 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
1075 (theKind == SketchPlugin_ConstraintAngle::ID()) ||
1076 (theKind == SketchPlugin_ConstraintDistanceHorizontal::ID()) ||
1077 (theKind == SketchPlugin_ConstraintDistanceVertical::ID()) ||
1078 (theKind == SketchPlugin_ConstraintDistanceAlongDir::ID());
1081 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
1083 static Events_ID EVENT_ATTR = Events_Loop::loop()->eventByName(EVENT_VISUAL_ATTRIBUTES);
1084 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1086 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1087 (getCurrentOperation());
1091 SketcherPrs_Tools::setPixelRatio(ModuleBase_Tools::currentPixelRatio());
1093 myModule->onViewTransformed();
1095 // Display all sketcher sub-Objects
1096 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
1097 double aSizeOfView = 0;
1098 std::shared_ptr<GeomAPI_Pnt> aCentralPoint;
1099 // Reset size of view from previous launches
1100 mySketchPlane->setSizeOfView(aSizeOfView, false, aCentralPoint);
1101 if (aFOperation->isEditOperation() &&
1102 mySketchPlane->getDefaultSizeOfView(myCurrentSketch, aSizeOfView, aCentralPoint)) {
1103 mySketchPlane->setSizeOfView(aSizeOfView, true, aCentralPoint);
1106 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
1107 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1109 // Hide sketcher result
1110 std::list<ResultPtr> aResults = myCurrentSketch->results();
1111 std::list<ResultPtr>::const_iterator aIt;
1112 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1113 (*aIt)->setDisplayed(false);
1115 myCurrentSketch->setDisplayed(false);
1117 // Remove invalid sketch entities
1118 std::set<FeaturePtr> anInvalidFeatures;
1119 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
1120 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1121 for (int i = 0; i < aNumberOfSubs; i++) {
1122 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1123 if (aFeature.get()) {
1124 if (!aFactory->validate(aFeature))
1125 anInvalidFeatures.insert(aFeature);
1128 if (!anInvalidFeatures.empty()) {
1129 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1130 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
1132 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
1133 aLast = anInvalidFeatures.end();
1134 // separate features to references to parameter features and references to others
1135 QStringList anInvalidFeatureNames;
1136 for (; anIt != aLast; anIt++) {
1137 FeaturePtr aFeature = *anIt;
1139 anInvalidFeatureNames.append(QString::fromStdWString(aFeature->name()));
1141 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
1142 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
1143 std::set<FeaturePtr> aFeatureRefsToDelete;
1144 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
1145 aFeatureRefsToDelete, aPrefixInfo)) {
1146 if (!aFeatureRefsToDelete.empty())
1147 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1148 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
1149 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1150 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
1151 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
1155 // update state of overconstraint listener should be done before sketch features/results
1156 // display (as the display will ask custom color from the listener)
1157 myModule->overconstraintListener()->setActive(true);
1158 // Display sketcher objects
1160 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1161 aNumberOfSubs = myCurrentSketch->numberOfSubs();
1162 for (int i = 0; i < aNumberOfSubs; i++) {
1163 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1164 #ifdef DEBUG_SKETCHER_ENTITIES
1165 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1167 std::list<ResultPtr> aFeatResults = aFeature->results();
1168 for (aIt = aFeatResults.begin(); aIt != aFeatResults.end(); ++aIt) {
1169 if ((*aIt)->isDisplayed())
1170 // Display object if it was created outside of GUI
1171 aECreator->sendUpdated((*aIt), EVENT_DISP);
1173 (*aIt)->setDisplayed(true);
1175 if (aFeature->isDisplayed())
1176 aECreator->sendUpdated(aFeature, EVENT_DISP);
1178 aFeature->setDisplayed(true);
1179 aECreator->sendUpdated(aFeature, EVENT_ATTR);
1181 #ifdef DEBUG_SKETCHER_ENTITIES
1182 QString anInfoStr = anInfo.join(";\t");
1183 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1186 std::shared_ptr<GeomAPI_Pln> aPln;
1187 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1188 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1189 if (!aFilter.IsNull())
1190 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1192 workshop()->selectionActivate()->updateSelectionFilters();
1193 workshop()->selectionActivate()->updateSelectionModes();
1195 Events_Loop::loop()->flush(EVENT_ATTR);
1196 Events_Loop::loop()->flush(EVENT_DISP);
1198 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1200 workshop()->viewer()->set2dMode(true);
1202 PartSet_Fitter* aFitter = new PartSet_Fitter(this);
1203 myModule->workshop()->viewer()->setFitter(aFitter);
1206 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1208 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1209 PartSet_Fitter* aFitter = (PartSet_Fitter*)myModule->workshop()->viewer()->fitter();
1210 myModule->workshop()->viewer()->setFitter(0);
1213 myIsMouseOverWindow = false;
1214 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1215 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1216 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1218 if (myExternalPointsMgr) {
1219 delete myExternalPointsMgr;
1220 myExternalPointsMgr = 0;
1222 onShowPoints(false);
1224 DataPtr aData = myCurrentSketch->data();
1225 if (!aData->isValid()) {
1226 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1227 // The sketch was aborted
1228 myCurrentSketch = CompositeFeaturePtr();
1229 mySketchPlane->eraseSketchPlane(myModule->workshop());
1231 // Erase all sketcher objects
1232 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1233 foreach (ObjectPtr aObj, aObjects) {
1234 DataPtr aObjData = aObj->data();
1235 if (!aObjData->isValid())
1236 aObj->setDisplayed(false);
1240 // Hide all sketcher sub-Objects
1241 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1242 for (int i = 0; i < aNumberOfSubs; i++) {
1243 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1244 std::list<ResultPtr> aResults = aFeature->results();
1245 std::list<ResultPtr>::const_iterator aIt;
1246 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1247 (*aIt)->setDisplayed(false);
1249 aFeature->setDisplayed(false);
1251 // Display sketcher result
1252 std::list<ResultPtr> aResults = myCurrentSketch->results();
1253 std::list<ResultPtr>::const_iterator aIt;
1254 Events_Loop* aLoop = Events_Loop::loop();
1255 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1257 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1259 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1260 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1261 (*aIt)->setDisplayed(true);
1262 // this display event is needed because sketch already may have "displayed" state,
1263 // but not displayed while it is still active (issue 613, abort of existing sketch)
1264 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1267 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1268 myCurrentSketch->setDisplayed(true);
1270 myCurrentSketch = CompositeFeaturePtr();
1271 mySketchPlane->eraseSketchPlane(myModule->workshop());
1273 Events_Loop::loop()->flush(aDispEvent);
1275 workshop()->selectionActivate()->updateSelectionFilters();
1276 workshop()->selectionActivate()->updateSelectionModes();
1277 workshop()->viewer()->set2dMode(false);
1280 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1282 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1283 QCursor* aCurrentCursor = QApplication::overrideCursor();
1284 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1285 QApplication::setOverrideCursor(PartSet_Tools::getOperationCursor());
1286 //#ifdef DEBUG_CURSOR
1287 // qDebug("startNestedSketch() : Qt::CrossCursor");
1293 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1295 myIsMouseOverViewProcessed = true;
1296 operationMgr()->onValidateOperation();
1297 // when sketch nested operation is stopped the cursor should be restored unconditionally
1298 if (canChangeCursor(theOperation)) {
1299 QApplication::restoreOverrideCursor();
1301 qDebug("stopNestedSketch() : None");
1304 /// improvement to deselect automatically all eventual selected objects, when
1305 // returning to the neutral point of the Sketcher
1306 bool isClearSelectionPossible = true;
1307 if (myIsEditLaunching) {
1308 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1311 FeaturePtr aFeature = aFOperation->feature();
1312 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1313 isClearSelectionPossible = false;
1317 if (isClearSelectionPossible)
1318 workshop()->selector()->clearSelection();
1319 if (myPointsHighlight.size())
1323 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1325 if (isNestedCreateOperation(theOperation, activeSketch())) {
1326 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1329 FeaturePtr aFeature = aFOperation->feature();
1330 // it is necessary to check the the feature data validity because
1331 // some kind of features are removed by an operation commit(the macro state of a feature)
1332 if (aFeature.get() && aFeature->data()->isValid()) {
1333 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1339 bool PartSet_SketcherMgr::sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType)
1341 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1344 void PartSet_SketcherMgr::registerSelectionFilter(
1345 const ModuleBase_SelectionFilterType theFilterType, const Handle(SelectMgr_Filter)& theFilter)
1347 mySelectionFilterTypes.insert(theFilterType);
1348 myModule->registerSelectionFilter(theFilterType, theFilter);
1351 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1353 bool isOperationStopped = false;
1354 ModuleBase_Operation* anOperation = getCurrentOperation();
1355 if(anOperation && isNestedSketchOperation(anOperation)) {
1356 // Set final definitions if they are necessary
1357 //propertyPanelDefined(aOperation);
1358 /// Commit sketcher operations automatically
1359 /// distance operation are able to show popup editor to modify the distance value
1360 /// after entering the value, the operation should be committed/aborted(by Esc key)
1361 bool aCanCommitOperation = true;
1362 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1364 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1365 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1366 aCanCommitOperation);
1367 if (!aValueAccepted)
1368 return isOperationStopped;
1371 if (aCanCommitOperation)
1372 isOperationStopped = anOperation->commit();
1374 anOperation->abort();
1375 isOperationStopped = true;
1378 return isOperationStopped;
1381 bool PartSet_SketcherMgr::canUndo() const
1383 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1386 bool PartSet_SketcherMgr::canRedo() const
1388 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1391 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1393 bool aCanErase = true;
1394 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1395 if (myCurrentSketch.get()) {
1396 return !isObjectOfSketch(theObject);
1401 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1403 bool aCanDisplay = true;
1405 bool aHasActiveSketch = activeSketch().get() != NULL;
1406 if (aHasActiveSketch) {
1407 // 1. the sketch feature should not be displayed during the sketch active operation
1408 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1409 // nested features can be visualized
1410 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1411 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1412 aCanDisplay = false;
1414 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1415 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1416 /// some sketch entities should be never shown, e.g. projection feature
1417 if (aSketchFeature.get())
1418 aCanDisplay = aSketchFeature->canBeDisplayed();
1420 else { // there are no an active sketch
1421 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1422 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1423 if (aFeature.get() != NULL) {
1424 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1425 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1426 if (aSketchFeature.get()) {
1427 aCanDisplay = false;
1432 // 3. the method should not filter the objects, which are not related to the current operation.
1433 // The object is filtered just if it is a current operation feature or this feature result
1435 bool isObjectFound = false;
1436 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1437 (getCurrentOperation());
1439 FeaturePtr aFeature = aFOperation->feature();
1440 if (aFeature.get()) {
1441 std::list<ResultPtr> aResults = aFeature->results();
1442 if (theObject == aFeature)
1443 isObjectFound = true;
1445 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1446 for (; anIt != aLast && !isObjectFound; anIt++) {
1447 isObjectFound = *anIt == theObject;
1452 if (isObjectFound) {
1453 // 4. For created nested feature operation do not display the created feature if
1454 // the mouse curstor leaves the OCC window.
1455 // The correction cases, which ignores this condition:
1456 // a. the property panel values modification
1457 // b. the popup menu activated
1458 // c. widget editor control
1459 #ifndef DEBUG_DO_NOT_BY_ENTER
1460 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1461 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1462 ModuleBase_WidgetEditor* anEditorWdg =
1463 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1464 // the active widget editor should not influence here. The presentation should be visible
1465 // always when this widget is active.
1466 if (!anEditorWdg && !myIsPopupMenuActive) {
1467 // during a nested create operation, the feature is redisplayed only
1468 // if the mouse over view
1469 // of there was a value modified in the property panel after the mouse left the view
1470 aCanDisplay = canDisplayCurrentCreatedFeature();
1477 // checks the sketcher constraints visibility according to active sketch check box states
1479 bool aProcessed = false;
1480 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1481 if (aFeature.get()) {
1482 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1484 aCanDisplay = aConstraintDisplayed;
1491 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1492 const PartSet_Tools::ConstraintVisibleState& theState,
1493 bool& isProcessed) const
1495 bool aSwitchedOn = true;
1497 const QStringList& aConstrIds = constraintsIdList();
1499 std::string aKind = theFeature->getKind();
1500 if (aConstrIds.contains(QString(aKind.c_str()))) {
1502 case PartSet_Tools::Dimensional: {
1503 bool isDistance = isDistanceKind(aKind);
1506 aSwitchedOn = myIsConstraintsShown[theState];
1510 case PartSet_Tools::Geometrical: {
1511 bool isGeometrical = !isDistanceKind(aKind);
1512 if (isGeometrical) {
1514 aSwitchedOn = myIsConstraintsShown[theState];
1518 case PartSet_Tools::Any: {
1520 bool isDistance = isDistanceKind(aKind);
1522 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1524 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1534 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1536 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1537 (getCurrentOperation());
1538 if (aFOperation && myCurrentSketch.get()) {
1539 // find results of the current operation
1540 // these results should not be proposed to be deleted
1541 FeaturePtr anOperationFeature = aFOperation->feature();
1542 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1543 std::set<ResultPtr> anOperationResults;
1544 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1545 aRLast = anOperationResultList.end();
1546 for (; aRIt != aRLast; aRIt++)
1547 anOperationResults.insert(*aRIt);
1549 std::set<FeaturePtr> anObjectsToBeDeleted;
1550 QStringList anObjectsToBeDeletedNames;
1551 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1552 for (; anIt != aLast; anIt++) {
1553 ObjectPtr anObject = *anIt;
1554 bool aCanErase = true;
1555 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1556 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1557 // the result is found between current feature results
1558 if (anOperationResults.find(aResult) != anOperationResults.end())
1561 if (aResult.get()) {
1562 // Display sketcher objects
1563 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1564 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1565 std::list<ResultPtr> aResults = aFeature->results();
1566 std::list<ResultPtr>::const_iterator anIt;
1567 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1568 aCanErase = *anIt != aResult;
1573 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1574 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1575 anObjectsToBeDeleted.insert(aFeature);
1576 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1580 if (!anObjectsToBeDeleted.empty()) {
1581 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1582 QString aMessage = tr("The following features have incorrect presentation and \
1583 will be hidden: %1. Would you like to delete them?")
1584 .arg(aFeatureNames);
1585 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1586 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1587 QMessageBox::Cancel);
1588 if (anAnswer == QMessageBox::Ok) {
1589 QObjectPtrList anObjects;
1590 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1591 aLast = anObjectsToBeDeleted.end();
1592 for (; anIt != aLast; anIt++)
1593 anObjects.append(*anIt);
1594 SessionPtr aMgr = ModelAPI_Session::get();
1595 DocumentPtr aDoc = aMgr->activeDocument();
1596 bool aIsOp = aMgr->isOperation();
1598 aMgr->startOperation();
1599 workshop()->deleteFeatures(anObjects);
1600 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1601 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1602 //Events_Loop::loop()->flush(aDeletedEvent);
1603 //Events_Loop::loop()->flush(aRedispEvent);
1606 aMgr->finishOperation();
1612 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1614 bool aCanDisplay = myIsMouseOverWindow;
1616 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1618 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1623 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1625 return isNestedCreateOperation(theOperation, activeSketch()) ||
1626 myModule->sketchReentranceMgr()->isInternalEditActive();
1629 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1631 return myIsConstraintsShown;
1634 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1636 if (!myCurrentSketch.get())
1638 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1639 if (anObjectFeature.get()) {
1640 int aSize = myCurrentSketch->numberOfSubs();
1641 FeaturePtr aCurrentFeature;
1642 for (int i = 0; i < aSize; i++) {
1643 aCurrentFeature = myCurrentSketch->subFeature(i);
1644 if (myCurrentSketch->subFeature(i) == anObjectFeature)
1651 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1653 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1654 if (!aFilter.IsNull())
1655 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1657 workshop()->selectionActivate()->updateSelectionModes();
1660 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1661 ModuleBase_IWorkshop* theWorkshop,
1662 bool& theCanCommitOperation)
1664 bool isValueAccepted = false;
1665 theCanCommitOperation = false;
1667 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1669 FeaturePtr aFeature = aFOperation->feature();
1670 // editor is shown only if all attribute references are filled by preseletion
1671 bool anAllRefAttrInitialized = true;
1673 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1674 ModelAPI_AttributeRefAttr::typeId());
1675 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1676 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1677 anAllRefAttrInitialized = (*anIt)->isInitialized();
1679 if (anAllRefAttrInitialized) {
1680 // Activate dimension value editing on double click
1681 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1682 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1683 // Find corresponded widget to activate value editing
1684 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1685 if (aWgt->attributeID() == "ConstraintValue") {
1686 // the featue should be displayed in order to find the AIS text position,
1687 // the place where the editor will be shown
1688 aFeature->setDisplayed(true);
1689 /// the execute is necessary to perform in the feature compute for flyout position
1690 aFeature->execute();
1692 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1693 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1695 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1697 int aX = 0, anY = 0;
1699 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1700 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1701 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1702 Handle(AIS_InteractiveObject) anAISIO;
1703 if (anAIS.get() != NULL) {
1704 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1706 if (anAIS.get() != NULL) {
1707 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1709 if (!anAISIO.IsNull()) {
1710 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1711 if (!aDim.IsNull()) {
1712 gp_Pnt aPosition = aDim->GetTextPosition();
1714 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1715 Handle(V3d_View) aView = aViewer->activeView();
1717 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1719 QWidget* aViewPort = aViewer->activeViewPort();
1720 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1725 anEditor->setCursorPosition(aX, anY);
1726 isValueAccepted = anEditor->showPopupEditor(false);
1727 theCanCommitOperation = true;
1733 return isValueAccepted;
1736 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1737 const FeaturePtr& theSketch,
1738 ModuleBase_IWorkshop* theWorkshop,
1739 const FeatureToSelectionMap& theSelection,
1740 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1742 if (theFeature.get() == NULL)
1745 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1746 SelectionInfo anInfo = anIt.value();
1747 std::map<AttributePtr, int> aSelectedAttributes = anInfo.myAttributes;
1748 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1750 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1751 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1753 // 1. found the feature's owners. Check the AIS objects of the constructions
1754 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1755 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1756 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1758 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1759 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1760 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1761 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1762 if (!anOwner.IsNull())
1763 theOwnersToSelect.Add(anOwner);
1767 // 2. found the feature results's owners
1768 std::list<ResultPtr> aResults = theFeature->results();
1769 std::list<ResultPtr>::const_iterator aIt;
1771 bool isSameShape = false;
1772 if (aResults.size() > 0) {
1773 ResultPtr aFirstResult = theFeature->firstResult();
1774 if (aFirstResult.get() && aFirstResult->shape().get()) {
1775 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1776 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1779 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1780 ResultPtr aResult = *aIt;
1781 AISObjectPtr aResAISObj = aDisplayer->getAISObject(aResult);
1782 if (aResAISObj.get() == NULL)
1784 Handle(AIS_InteractiveObject) anAISIO = aResAISObj->impl<Handle(AIS_InteractiveObject)>();
1786 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1787 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1788 bool aFoundLocalShape = false;
1789 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1790 Handle(StdSelect_BRepOwner) anOwner =
1791 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1792 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1794 const TopoDS_Shape& aShape = anOwner->Shape();
1795 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1796 if (aShapeType == TopAbs_VERTEX) {
1797 std::pair<AttributePtr, int> aPntAttrIndex =
1798 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1799 if (aPntAttrIndex.first.get() != NULL &&
1800 aSelectedAttributes.find(aPntAttrIndex.first) != aSelectedAttributes.end())
1801 theOwnersToSelect.Add(anOwner);
1802 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1803 theOwnersToSelect.Add(anOwner);
1806 else if (aShapeType == TopAbs_EDGE) {
1807 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1808 // try to restore local selection on Shape result
1809 // we can do this only if the shape was not changed
1810 theOwnersToSelect.Add(anOwner);
1811 aFoundLocalShape = true;
1816 if (!aFoundLocalShape) {
1817 // result owners are put in the list of selection only if local selected shapes were not
1819 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1820 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1821 Handle(StdSelect_BRepOwner) anOwner =
1822 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1823 if (anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1825 // select whole result
1826 theOwnersToSelect.Add(anOwner);
1833 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1834 const bool isToConnect)
1836 //Temporary commented as we do not modify values in property panel
1838 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1839 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1840 //connect(theWidget, SIGNAL(afterValuesChanged()),
1841 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1842 connect(theWidget, SIGNAL(afterValuesChanged()),
1843 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1846 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1847 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1848 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1849 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1850 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1851 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1855 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1857 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1858 (getCurrentOperation());
1860 if ((PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1861 isNestedSketchOperation(aFOperation)) &&
1862 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1863 FeaturePtr aFeature = aFOperation->feature();
1864 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1869 //void PartSet_SketcherMgr::customisePresentation(const ObjectPtr& theObject)
1871 // ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1872 // (getCurrentOperation());
1873 // if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1874 // isNestedSketchOperation(aFOperation)))
1875 // SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1877 // // update entities selection priorities
1878 // FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1879 // if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1880 // // update priority for feature
1881 // updateSelectionPriority(aFeature, aFeature);
1882 // // update priority for results of the feature
1883 // std::list<ResultPtr> aResults = aFeature->results();
1884 // std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1885 // for (; anIt != aLastIt; anIt++)
1886 // updateSelectionPriority(*anIt, aFeature);
1890 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1892 return myModule->workshop()->currentOperation();
1895 //**************************************************************
1896 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1898 ModuleBase_ModelWidget* aWidget = 0;
1899 ModuleBase_Operation* anOperation = getCurrentOperation();
1901 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1903 aWidget = aPanel->activeWidget();
1908 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1909 const bool isEditOperation,
1910 const bool isToDisplay,
1911 const bool isFlushRedisplay)
1913 #ifdef DEBUG_DO_NOT_BY_ENTER
1917 if (isEditOperation || !theFeature.get())
1920 // 1. change visibility of the object itself, here the presentable object is processed,
1921 // e.g. constraints features
1922 //FeaturePtr aFeature = aFOperation->feature();
1923 std::list<ResultPtr> aResults = theFeature->results();
1925 theFeature->setDisplayed(true);
1927 theFeature->setDisplayed(false);
1929 // change visibility of the object results, e.g. non-constraint features
1930 std::list<ResultPtr>::const_iterator aIt;
1931 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1933 (*aIt)->setDisplayed(true);
1936 (*aIt)->setDisplayed(false);
1939 if (isFlushRedisplay)
1940 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1943 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1944 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1946 if (!myCurrentSketch.get())
1949 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1950 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1951 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1953 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1954 aStoredPrs = aSelect->getHighlighted();
1956 QList<FeaturePtr> aFeatureList;
1957 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1958 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1959 ModuleBase_ISelection::AllControls);
1960 aStoredPrs.append(aSelected);
1963 // 1. it is necessary to save current selection in order to restore it after the features moving
1964 theCurrentSelection.clear();
1966 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1967 aLast = aStoredPrs.end();
1969 CompositeFeaturePtr aSketch = activeSketch();
1970 for (; anIt != aLast; anIt++) {
1971 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1972 ObjectPtr anObject = aPrs->object();
1973 if (!anObject.get())
1976 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1977 FeaturePtr aFeature;
1979 aFeature = ModelAPI_Feature::feature(aResult);
1981 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1983 if (!aFeature.get())
1986 std::set<AttributePtr> aSelectedAttributes;
1987 std::set<ResultPtr> aSelectedResults;
1988 SelectionInfo anInfo;
1989 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1990 anInfo = theCurrentSelection.find(aFeature).value();
1992 TopoDS_Shape aFirstShape;
1993 ResultPtr aFirstResult = aFeature->firstResult();
1994 if (aFirstResult.get() && aFirstResult->shape().get())
1995 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1996 anInfo.myFirstResultShape = aFirstShape;
1997 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1998 if (aResult.get()) {
1999 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
2000 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
2003 std::list<ResultPtr> aResults = aFeature->results();
2004 std::list<ResultPtr>::const_iterator aIt;
2005 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
2006 ResultPtr aCurResult = *aIt;
2007 getAttributesOrResults(anOwner, aFeature, aSketch, aCurResult,
2008 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
2011 theCurrentSelection[aFeature] = anInfo;
2013 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
2016 void PartSet_SketcherMgr::restoreSelection(
2017 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
2019 if (!myCurrentSketch.get())
2022 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
2023 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2024 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
2025 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
2026 aSLast = theCurrentSelection.end();
2027 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
2028 anOwnersToSelect.Clear();
2029 for (; aSIt != aSLast; aSIt++) {
2030 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
2033 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
2036 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
2038 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
2040 updateBySketchParameters(aType, theState);
2041 myModule->workshop()->viewer()->update();
2044 void PartSet_SketcherMgr::updateBySketchParameters(
2045 const PartSet_Tools::ConstraintVisibleState& theType,
2048 if (myCurrentSketch.get() == NULL)
2051 bool aPrevState = myIsConstraintsShown[theType];
2052 myIsConstraintsShown[theType] = theState;
2055 case PartSet_Tools::Geometrical:
2056 case PartSet_Tools::Dimensional: {
2057 if (aPrevState != theState) {
2058 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
2059 for (int i = 0; i < aNumberOfSubs; i++) {
2060 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
2061 bool aProcessed = false;
2062 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
2064 aSubFeature->setDisplayed(aConstraintDisplayed);
2066 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2070 case PartSet_Tools::Expressions: {
2071 if (aPrevState != theState) {
2072 /// call all sketch features redisplay, the expression state will be corrected in customize
2073 /// of distance presentation
2074 SketcherPrs_Tools::ParameterStyle aStyle = myIsConstraintsShown[PartSet_Tools::Expressions]
2075 ? SketcherPrs_Tools::ParameterText : SketcherPrs_Tools::ParameterValue;
2076 SketcherPrs_Tools::setParameterStyle(aStyle);
2077 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2078 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
2082 default: // [to avoid compilation warning]
2087 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
2088 FeaturePtr theFeature)
2090 if (!theObject.get() || !theFeature.get())
2093 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
2094 Handle(AIS_InteractiveObject) anAISIO;
2095 if (anAIS.get() != NULL) {
2096 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
2099 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
2100 int anAdditionalPriority = 0;
2102 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2103 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
2104 if (aSPFeature.get() != NULL) {
2106 // 2. Simple segments
2107 // 3. External objects (violet color)
2108 // 4. Auxiliary segments (dotted)
2109 // StdSelect_BRepSelectionTool::Load uses priority calculating:
2110 // Standard_Integer aPriority =
2111 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
2112 // Priority of Vertex is 8, edge(segment) is 7.
2113 // It might be not corrected as provides the condition above.
2114 bool isExternal = aSPFeature->isExternal();
2115 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
2117 if (!isExternal && !isAuxiliary)
2118 anAdditionalPriority = 30;
2121 anAdditionalPriority = 20;
2122 // auxiliary feature
2124 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
2125 // edges/vertices of local selection on not-sketch objects
2127 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
2128 if (!aResult.IsNull()) {
2129 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
2135 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
2137 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
2138 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
2139 return aConnector->workshop();
2142 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
2144 return workshop()->operationMgr();
2147 void PartSet_SketcherMgr::onShowPoints(bool toShow)
2149 if (!myCurrentSketch.get())
2151 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2152 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
2153 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
2155 bool aToUpdate = false;
2157 std::list<ResultPtr> aFreePoints = SketcherPrs_Tools::getFreePoints(myCurrentSketch);
2159 // Delete obsolete presentations
2160 std::list<ResultPtr> aDelList;
2161 foreach(ResultPtr aObj, myPointsHighlight.keys()) {
2162 bool aFound = (std::find(aFreePoints.begin(), aFreePoints.end(), aObj) != aFreePoints.end());
2164 aDelList.push_back(aObj);
2166 foreach(ResultPtr aObj, aDelList) {
2167 aContext->Remove(myPointsHighlight[aObj], false);
2169 myPointsHighlight.remove(aObj);
2172 // Display new objects
2173 QList<ResultPtr> aKeysList = myPointsHighlight.keys();
2174 std::list<ResultPtr>::const_iterator aIt;
2175 for (aIt = aFreePoints.cbegin(); aIt != aFreePoints.cend(); aIt++) {
2176 if (!aKeysList.contains(*aIt)) {
2177 GeomShapePtr aShapePtr = (*aIt)->shape();
2178 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
2179 Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape);
2180 aShapePrs->SetColor(Quantity_NOC_BLUE1);
2181 aShapePrs->SetZLayer(Graphic3d_ZLayerId_Top);
2182 Handle(Prs3d_Drawer) aDrawer = aShapePrs->Attributes();
2183 if (aDrawer->HasOwnPointAspect()) {
2184 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
2185 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
2186 aDrawer->PointAspect()->SetScale(2);
2189 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2));
2190 aContext->Display(aShapePrs, false);
2191 aContext->Deactivate(aShapePrs);
2192 myPointsHighlight[*aIt] = aShapePrs;
2198 foreach(Handle(AIS_Shape) aPrs, myPointsHighlight.values()) {
2199 aContext->Remove(aPrs, false);
2202 myPointsHighlight.clear();
2208 void PartSet_SketcherMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
2210 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOF_OBJECTS)) {
2211 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
2212 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
2213 std::set<ObjectPtr> aObjects = anUpdateMsg->objects();
2214 std::set<ObjectPtr>::const_iterator aIt;
2215 QList<ModuleBase_ViewerPrsPtr> aPrsList;
2216 for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
2217 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aIt);
2218 if (aFeature.get()) {
2219 std::list<ResultPtr> aRes = aFeature->results();
2220 std::list<ResultPtr>::const_iterator aRIt;
2221 for (aRIt = aRes.cbegin(); aRIt != aRes.cend(); ++aRIt) {
2222 ModuleBase_ViewerPrsPtr aPrsPtr(new ModuleBase_ViewerPrs(*aRIt));
2223 aPrsList.append(aPrsPtr);
2227 if (aPrsList.size() > 0) {
2228 myModule->workshop()->setSelected(aPrsList);
2233 bool isExternal(const ObjectPtr& theObject)
2235 AttributeSelectionPtr aAttr =
2236 theObject->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
2238 return aAttr->context().get() != NULL && !aAttr->isInvalid();
2242 bool isCopy(const ObjectPtr& theObject)
2244 AttributeBooleanPtr anAttr = theObject->data()->boolean(SketchPlugin_SketchEntity::COPY_ID());
2246 return anAttr->value();
2250 bool isIncludeToResult(const ObjectPtr& theObject)
2252 AttributeBooleanPtr anAttr;
2253 std::set<AttributePtr> aRefsToMe = theObject->data()->refsToMe();
2254 std::set<AttributePtr>::const_iterator aIt;
2255 for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) {
2256 if ((*aIt)->id() == SketchPlugin_Projection::PROJECTED_FEATURE_ID()) {
2257 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aIt)->owner());
2258 if (aFeature.get() && !aFeature->isMacro()) {
2259 anAttr = aFeature->data()->boolean(SketchPlugin_Projection::INCLUDE_INTO_RESULT());
2261 return anAttr->value();
2268 //**************************************************************************************
2269 std::vector<int> PartSet_SketcherMgr::colorOfObject(const ObjectPtr& theObject,
2270 const FeaturePtr& theFeature, bool isConstruction) const
2272 PartSet_OverconstraintListener* aOCListener = myModule->overconstraintListener();
2273 std::string aKind = theFeature->getKind();
2275 if (aOCListener->isConflictingObject(theObject)) {
2276 return Config_PropManager::color("Visualization", "sketch_overconstraint_color");
2278 if (isDistanceKind(aKind)) {
2279 return Config_PropManager::color("Visualization", "sketch_dimension_color");
2281 if (isExternal(theFeature))
2282 return Config_PropManager::color("Visualization", "sketch_external_color");
2284 if (aOCListener->isFullyConstrained()) {
2285 return Config_PropManager::color("Visualization", "sketch_fully_constrained_color");
2287 if (aKind == SketchPlugin_ConstraintCoincidence::ID())
2288 return std::vector<int>(3, 0);
2291 return Config_PropManager::color("Visualization", "sketch_auxiliary_color");
2293 return Config_PropManager::color("Visualization", "sketch_entity_color");
2296 //**************************************************************************************
2297 void PartSet_SketcherMgr::customizeSketchPresentation(const ObjectPtr& theObject,
2298 const AISObjectPtr& thePrs) const
2300 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
2302 // set color from preferences
2303 std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
2304 aFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
2305 bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
2307 std::vector<int> aColor = colorOfObject(theObject, aFeature, isConstruction);
2308 if (!aColor.empty()) {
2309 // The code below causes redisplay again
2310 if (ModelAPI_Session::get()->isOperation()) {
2311 AttributeIntArrayPtr aColorAttr = theObject->data()->intArray(ModelAPI_Result::COLOR_ID());
2312 if (aColorAttr.get()) {
2313 aColorAttr->setSize(3, false);
2314 // Set the color attribute in order do not use default colors in the presentation object
2315 for (int i = 0; i < 3; i++)
2316 aColorAttr->setValue(i, aColor[i], false);
2319 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
2322 int aShapeType = thePrs->getShapeType();
2323 // a compound is processed like the edge because the
2324 // arc feature uses the compound for presentable AIS
2325 if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
2328 int aWidth = Config_PropManager::integer("Visualization", "sketch_line_width");
2329 if (isExternal(aFeature)) {
2330 thePrs->setWidth(isIncludeToResult(aFeature)? aWidth : 1);
2333 std::string aKind = aFeature->getKind();
2334 if (isDistanceKind(aKind))
2337 if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
2338 if (isConstruction) {
2339 // Set axilliary line
2340 thePrs->setWidth(SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY());
2341 thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY());
2344 thePrs->setWidth(aWidth);
2345 thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE());
2348 else if (aShapeType == 7) { // otherwise this is a vertex
2349 // The width value do not have effect on the point presentation.
2350 // It is defined in order to extend selection area of the object.
2351 thePrs->setWidth(17);
2352 // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
2354 if (isCopy(aFeature) || !isIncludeToResult(aFeature)) {
2355 double aPrsWidth = thePrs->width();
2356 thePrs->setWidth(aPrsWidth / 2.5);
2359 double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
2360 thePrs->setDeflection(aDeflection);
2363 //*************************************************************************************
2364 void PartSet_Fitter::fitAll(Handle(V3d_View) theView)
2366 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
2368 ModuleBase_IWorkshop* aWorkshop = mySketchMgr->module()->workshop();
2369 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
2370 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
2373 int aNumberOfSubs = aSketch->numberOfSubs();
2374 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2375 for (int i = 0; i < aNumberOfSubs; i++) {
2376 FeaturePtr aFeature = aSketch->subFeature(i);
2377 if (aDisplayer->isVisible(aFeature)) {
2378 AISObjectPtr aAisPtr = aDisplayer->getAISObject(aFeature);
2379 Handle(AIS_InteractiveObject) aAisObj = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2380 if (!aAisObj->IsInfinite()) {
2382 aAisObj->BoundingBox(aBox);
2387 std::list<ResultPtr> aResults = aFeature->results();
2388 std::list<ResultPtr>::const_iterator aIt;
2390 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
2392 if (aRes->isDisplayed()) {
2393 FeaturePtr aCurFeature = ModelAPI_Feature::feature(aRes);
2394 if (aCurFeature.get()) {
2395 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2396 std::dynamic_pointer_cast<SketchPlugin_Feature>(aCurFeature);
2397 if (aSPFeature.get()) {
2399 aSPFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
2400 if (!(aSPFeature->isExternal() || isAxiliary)) {
2401 GeomShapePtr aShape = aRes->shape();
2402 aShape->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2404 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2413 if (aBndBox.IsVoid())
2416 theView->FitAll(aBndBox, 0.01);