1 // Copyright (C) 2014-2020 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" << "SketchRectangle";
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 if (aFOperation->isEditOperation() &&
1100 mySketchPlane->getDefaultSizeOfView(myCurrentSketch, aSizeOfView, aCentralPoint)) {
1101 mySketchPlane->setSizeOfView(aSizeOfView, true, aCentralPoint);
1104 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
1105 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1107 // Hide sketcher result
1108 std::list<ResultPtr> aResults = myCurrentSketch->results();
1109 std::list<ResultPtr>::const_iterator aIt;
1110 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1111 (*aIt)->setDisplayed(false);
1113 myCurrentSketch->setDisplayed(false);
1115 // Remove invalid sketch entities
1116 std::set<FeaturePtr> anInvalidFeatures;
1117 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
1118 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1119 for (int i = 0; i < aNumberOfSubs; i++) {
1120 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1121 if (aFeature.get()) {
1122 if (!aFactory->validate(aFeature))
1123 anInvalidFeatures.insert(aFeature);
1126 if (!anInvalidFeatures.empty()) {
1127 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1128 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
1130 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
1131 aLast = anInvalidFeatures.end();
1132 // separate features to references to parameter features and references to others
1133 QStringList anInvalidFeatureNames;
1134 for (; anIt != aLast; anIt++) {
1135 FeaturePtr aFeature = *anIt;
1137 anInvalidFeatureNames.append(QString::fromStdWString(aFeature->name()));
1139 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
1140 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
1141 std::set<FeaturePtr> aFeatureRefsToDelete;
1142 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
1143 aFeatureRefsToDelete, aPrefixInfo)) {
1144 if (!aFeatureRefsToDelete.empty())
1145 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1146 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
1147 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1148 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
1149 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
1153 // update state of overconstraint listener should be done before sketch features/results
1154 // display (as the display will ask custom color from the listener)
1155 myModule->overconstraintListener()->setActive(true);
1156 // Display sketcher objects
1158 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1159 aNumberOfSubs = myCurrentSketch->numberOfSubs();
1160 for (int i = 0; i < aNumberOfSubs; i++) {
1161 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1162 #ifdef DEBUG_SKETCHER_ENTITIES
1163 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1165 std::list<ResultPtr> aFeatResults = aFeature->results();
1166 for (aIt = aFeatResults.begin(); aIt != aFeatResults.end(); ++aIt) {
1167 if ((*aIt)->isDisplayed())
1168 // Display object if it was created outside of GUI
1169 aECreator->sendUpdated((*aIt), EVENT_DISP);
1171 (*aIt)->setDisplayed(true);
1173 if (aFeature->isDisplayed())
1174 aECreator->sendUpdated(aFeature, EVENT_DISP);
1176 aFeature->setDisplayed(true);
1177 aECreator->sendUpdated(aFeature, EVENT_ATTR);
1179 #ifdef DEBUG_SKETCHER_ENTITIES
1180 QString anInfoStr = anInfo.join(";\t");
1181 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1184 std::shared_ptr<GeomAPI_Pln> aPln;
1185 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1186 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1187 if (!aFilter.IsNull())
1188 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1190 workshop()->selectionActivate()->updateSelectionFilters();
1191 workshop()->selectionActivate()->updateSelectionModes();
1193 Events_Loop::loop()->flush(EVENT_ATTR);
1194 Events_Loop::loop()->flush(EVENT_DISP);
1196 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1198 workshop()->viewer()->set2dMode(true);
1200 PartSet_Fitter* aFitter = new PartSet_Fitter(this);
1201 myModule->workshop()->viewer()->setFitter(aFitter);
1204 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1206 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1207 PartSet_Fitter* aFitter = (PartSet_Fitter*)myModule->workshop()->viewer()->fitter();
1208 myModule->workshop()->viewer()->setFitter(0);
1211 myIsMouseOverWindow = false;
1212 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1213 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1214 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1216 if (myExternalPointsMgr) {
1217 delete myExternalPointsMgr;
1218 myExternalPointsMgr = 0;
1220 onShowPoints(false);
1222 DataPtr aData = myCurrentSketch->data();
1223 if (!aData->isValid()) {
1224 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1225 // The sketch was aborted
1226 myCurrentSketch = CompositeFeaturePtr();
1227 mySketchPlane->eraseSketchPlane(myModule->workshop());
1229 // Erase all sketcher objects
1230 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1231 foreach (ObjectPtr aObj, aObjects) {
1232 DataPtr aObjData = aObj->data();
1233 if (!aObjData->isValid())
1234 aObj->setDisplayed(false);
1238 // Hide all sketcher sub-Objects
1239 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1240 for (int i = 0; i < aNumberOfSubs; i++) {
1241 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1242 std::list<ResultPtr> aResults = aFeature->results();
1243 std::list<ResultPtr>::const_iterator aIt;
1244 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1245 (*aIt)->setDisplayed(false);
1247 aFeature->setDisplayed(false);
1249 // Display sketcher result
1250 std::list<ResultPtr> aResults = myCurrentSketch->results();
1251 std::list<ResultPtr>::const_iterator aIt;
1252 Events_Loop* aLoop = Events_Loop::loop();
1253 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1255 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1257 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1258 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1259 (*aIt)->setDisplayed(true);
1260 // this display event is needed because sketch already may have "displayed" state,
1261 // but not displayed while it is still active (issue 613, abort of existing sketch)
1262 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1265 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1266 myCurrentSketch->setDisplayed(true);
1268 myCurrentSketch = CompositeFeaturePtr();
1269 mySketchPlane->eraseSketchPlane(myModule->workshop());
1271 Events_Loop::loop()->flush(aDispEvent);
1273 workshop()->selectionActivate()->updateSelectionFilters();
1274 workshop()->selectionActivate()->updateSelectionModes();
1275 workshop()->viewer()->set2dMode(false);
1278 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1280 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1281 QCursor* aCurrentCursor = QApplication::overrideCursor();
1282 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1283 QApplication::setOverrideCursor(PartSet_Tools::getOperationCursor());
1284 //#ifdef DEBUG_CURSOR
1285 // qDebug("startNestedSketch() : Qt::CrossCursor");
1291 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1293 myIsMouseOverViewProcessed = true;
1294 operationMgr()->onValidateOperation();
1295 // when sketch nested operation is stopped the cursor should be restored unconditionally
1296 if (canChangeCursor(theOperation)) {
1297 QApplication::restoreOverrideCursor();
1299 qDebug("stopNestedSketch() : None");
1302 /// improvement to deselect automatically all eventual selected objects, when
1303 // returning to the neutral point of the Sketcher
1304 bool isClearSelectionPossible = true;
1305 if (myIsEditLaunching) {
1306 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1309 FeaturePtr aFeature = aFOperation->feature();
1310 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1311 isClearSelectionPossible = false;
1315 if (isClearSelectionPossible)
1316 workshop()->selector()->clearSelection();
1317 if (myPointsHighlight.size())
1321 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1323 if (isNestedCreateOperation(theOperation, activeSketch())) {
1324 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1327 FeaturePtr aFeature = aFOperation->feature();
1328 // it is necessary to check the the feature data validity because
1329 // some kind of features are removed by an operation commit(the macro state of a feature)
1330 if (aFeature.get() && aFeature->data()->isValid()) {
1331 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1337 bool PartSet_SketcherMgr::sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType)
1339 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1342 void PartSet_SketcherMgr::registerSelectionFilter(
1343 const ModuleBase_SelectionFilterType theFilterType, const Handle(SelectMgr_Filter)& theFilter)
1345 mySelectionFilterTypes.insert(theFilterType);
1346 myModule->registerSelectionFilter(theFilterType, theFilter);
1349 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1351 bool isOperationStopped = false;
1352 ModuleBase_Operation* anOperation = getCurrentOperation();
1353 if(anOperation && isNestedSketchOperation(anOperation)) {
1354 // Set final definitions if they are necessary
1355 //propertyPanelDefined(aOperation);
1356 /// Commit sketcher operations automatically
1357 /// distance operation are able to show popup editor to modify the distance value
1358 /// after entering the value, the operation should be committed/aborted(by Esc key)
1359 bool aCanCommitOperation = true;
1360 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1362 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1363 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1364 aCanCommitOperation);
1365 if (!aValueAccepted)
1366 return isOperationStopped;
1369 if (aCanCommitOperation)
1370 isOperationStopped = anOperation->commit();
1372 anOperation->abort();
1373 isOperationStopped = true;
1376 return isOperationStopped;
1379 bool PartSet_SketcherMgr::canUndo() const
1381 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1384 bool PartSet_SketcherMgr::canRedo() const
1386 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1389 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1391 bool aCanErase = true;
1392 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1393 if (myCurrentSketch.get()) {
1394 return !isObjectOfSketch(theObject);
1399 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1401 bool aCanDisplay = true;
1403 bool aHasActiveSketch = activeSketch().get() != NULL;
1404 if (aHasActiveSketch) {
1405 // 1. the sketch feature should not be displayed during the sketch active operation
1406 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1407 // nested features can be visualized
1408 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1409 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1410 aCanDisplay = false;
1412 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1413 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1414 /// some sketch entities should be never shown, e.g. projection feature
1415 if (aSketchFeature.get())
1416 aCanDisplay = aSketchFeature->canBeDisplayed();
1418 else { // there are no an active sketch
1419 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1420 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1421 if (aFeature.get() != NULL) {
1422 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1423 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1424 if (aSketchFeature.get()) {
1425 aCanDisplay = false;
1430 // 3. the method should not filter the objects, which are not related to the current operation.
1431 // The object is filtered just if it is a current operation feature or this feature result
1433 bool isObjectFound = false;
1434 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1435 (getCurrentOperation());
1437 FeaturePtr aFeature = aFOperation->feature();
1438 if (aFeature.get()) {
1439 std::list<ResultPtr> aResults = aFeature->results();
1440 if (theObject == aFeature)
1441 isObjectFound = true;
1443 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1444 for (; anIt != aLast && !isObjectFound; anIt++) {
1445 isObjectFound = *anIt == theObject;
1450 if (isObjectFound) {
1451 // 4. For created nested feature operation do not display the created feature if
1452 // the mouse curstor leaves the OCC window.
1453 // The correction cases, which ignores this condition:
1454 // a. the property panel values modification
1455 // b. the popup menu activated
1456 // c. widget editor control
1457 #ifndef DEBUG_DO_NOT_BY_ENTER
1458 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1459 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1460 ModuleBase_WidgetEditor* anEditorWdg =
1461 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1462 // the active widget editor should not influence here. The presentation should be visible
1463 // always when this widget is active.
1464 if (!anEditorWdg && !myIsPopupMenuActive) {
1465 // during a nested create operation, the feature is redisplayed only
1466 // if the mouse over view
1467 // of there was a value modified in the property panel after the mouse left the view
1468 aCanDisplay = canDisplayCurrentCreatedFeature();
1475 // checks the sketcher constraints visibility according to active sketch check box states
1477 bool aProcessed = false;
1478 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1479 if (aFeature.get()) {
1480 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1482 aCanDisplay = aConstraintDisplayed;
1489 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1490 const PartSet_Tools::ConstraintVisibleState& theState,
1491 bool& isProcessed) const
1493 bool aSwitchedOn = true;
1495 const QStringList& aConstrIds = constraintsIdList();
1497 std::string aKind = theFeature->getKind();
1498 if (aConstrIds.contains(QString(aKind.c_str()))) {
1500 case PartSet_Tools::Dimensional: {
1501 bool isDistance = isDistanceKind(aKind);
1504 aSwitchedOn = myIsConstraintsShown[theState];
1508 case PartSet_Tools::Geometrical: {
1509 bool isGeometrical = !isDistanceKind(aKind);
1510 if (isGeometrical) {
1512 aSwitchedOn = myIsConstraintsShown[theState];
1516 case PartSet_Tools::Any: {
1518 bool isDistance = isDistanceKind(aKind);
1520 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1522 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1532 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1534 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1535 (getCurrentOperation());
1536 if (aFOperation && myCurrentSketch.get()) {
1537 // find results of the current operation
1538 // these results should not be proposed to be deleted
1539 FeaturePtr anOperationFeature = aFOperation->feature();
1540 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1541 std::set<ResultPtr> anOperationResults;
1542 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1543 aRLast = anOperationResultList.end();
1544 for (; aRIt != aRLast; aRIt++)
1545 anOperationResults.insert(*aRIt);
1547 std::set<FeaturePtr> anObjectsToBeDeleted;
1548 QStringList anObjectsToBeDeletedNames;
1549 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1550 for (; anIt != aLast; anIt++) {
1551 ObjectPtr anObject = *anIt;
1552 bool aCanErase = true;
1553 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1554 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1555 // the result is found between current feature results
1556 if (anOperationResults.find(aResult) != anOperationResults.end())
1559 if (aResult.get()) {
1560 // Display sketcher objects
1561 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1562 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1563 std::list<ResultPtr> aResults = aFeature->results();
1564 std::list<ResultPtr>::const_iterator anIt;
1565 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1566 aCanErase = *anIt != aResult;
1571 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1572 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1573 anObjectsToBeDeleted.insert(aFeature);
1574 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1578 if (!anObjectsToBeDeleted.empty()) {
1579 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1580 QString aMessage = tr("The following features have incorrect presentation and \
1581 will be hidden: %1. Would you like to delete them?")
1582 .arg(aFeatureNames);
1583 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1584 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1585 QMessageBox::Cancel);
1586 if (anAnswer == QMessageBox::Ok) {
1587 QObjectPtrList anObjects;
1588 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1589 aLast = anObjectsToBeDeleted.end();
1590 for (; anIt != aLast; anIt++)
1591 anObjects.append(*anIt);
1592 SessionPtr aMgr = ModelAPI_Session::get();
1593 DocumentPtr aDoc = aMgr->activeDocument();
1594 bool aIsOp = aMgr->isOperation();
1596 aMgr->startOperation();
1597 workshop()->deleteFeatures(anObjects);
1598 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1599 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1600 //Events_Loop::loop()->flush(aDeletedEvent);
1601 //Events_Loop::loop()->flush(aRedispEvent);
1604 aMgr->finishOperation();
1610 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1612 bool aCanDisplay = myIsMouseOverWindow;
1614 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1616 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1621 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1623 return isNestedCreateOperation(theOperation, activeSketch()) ||
1624 myModule->sketchReentranceMgr()->isInternalEditActive();
1627 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1629 return myIsConstraintsShown;
1632 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1634 if (!myCurrentSketch.get())
1636 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1637 if (anObjectFeature.get()) {
1638 int aSize = myCurrentSketch->numberOfSubs();
1639 FeaturePtr aCurrentFeature;
1640 for (int i = 0; i < aSize; i++) {
1641 aCurrentFeature = myCurrentSketch->subFeature(i);
1642 if (myCurrentSketch->subFeature(i) == anObjectFeature)
1649 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1651 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1652 if (!aFilter.IsNull())
1653 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1655 workshop()->selectionActivate()->updateSelectionModes();
1658 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1659 ModuleBase_IWorkshop* theWorkshop,
1660 bool& theCanCommitOperation)
1662 bool isValueAccepted = false;
1663 theCanCommitOperation = false;
1665 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1667 FeaturePtr aFeature = aFOperation->feature();
1668 // editor is shown only if all attribute references are filled by preseletion
1669 bool anAllRefAttrInitialized = true;
1671 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1672 ModelAPI_AttributeRefAttr::typeId());
1673 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1674 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1675 anAllRefAttrInitialized = (*anIt)->isInitialized();
1677 if (anAllRefAttrInitialized) {
1678 // Activate dimension value editing on double click
1679 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1680 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1681 // Find corresponded widget to activate value editing
1682 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1683 if (aWgt->attributeID() == "ConstraintValue") {
1684 // the featue should be displayed in order to find the AIS text position,
1685 // the place where the editor will be shown
1686 aFeature->setDisplayed(true);
1687 /// the execute is necessary to perform in the feature compute for flyout position
1688 aFeature->execute();
1690 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1691 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1693 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1695 int aX = 0, anY = 0;
1697 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1698 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1699 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1700 Handle(AIS_InteractiveObject) anAISIO;
1701 if (anAIS.get() != NULL) {
1702 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1704 if (anAIS.get() != NULL) {
1705 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1707 if (!anAISIO.IsNull()) {
1708 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1709 if (!aDim.IsNull()) {
1710 gp_Pnt aPosition = aDim->GetTextPosition();
1712 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1713 Handle(V3d_View) aView = aViewer->activeView();
1715 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1717 QWidget* aViewPort = aViewer->activeViewPort();
1718 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1723 anEditor->setCursorPosition(aX, anY);
1724 isValueAccepted = anEditor->showPopupEditor(false);
1725 theCanCommitOperation = true;
1731 return isValueAccepted;
1734 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1735 const FeaturePtr& theSketch,
1736 ModuleBase_IWorkshop* theWorkshop,
1737 const FeatureToSelectionMap& theSelection,
1738 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1740 if (theFeature.get() == NULL)
1743 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1744 SelectionInfo anInfo = anIt.value();
1745 std::map<AttributePtr, int> aSelectedAttributes = anInfo.myAttributes;
1746 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1748 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1749 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1751 // 1. found the feature's owners. Check the AIS objects of the constructions
1752 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1753 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1754 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1756 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1757 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1758 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1759 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1760 if (!anOwner.IsNull())
1761 theOwnersToSelect.Add(anOwner);
1765 // 2. found the feature results's owners
1766 std::list<ResultPtr> aResults = theFeature->results();
1767 std::list<ResultPtr>::const_iterator aIt;
1769 bool isSameShape = false;
1770 if (aResults.size() > 0) {
1771 ResultPtr aFirstResult = theFeature->firstResult();
1772 if (aFirstResult.get() && aFirstResult->shape().get()) {
1773 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1774 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1777 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1778 ResultPtr aResult = *aIt;
1779 AISObjectPtr aResAISObj = aDisplayer->getAISObject(aResult);
1780 if (aResAISObj.get() == NULL)
1782 Handle(AIS_InteractiveObject) anAISIO = aResAISObj->impl<Handle(AIS_InteractiveObject)>();
1784 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1785 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1786 bool aFoundLocalShape = false;
1787 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1788 Handle(StdSelect_BRepOwner) anOwner =
1789 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1790 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1792 const TopoDS_Shape& aShape = anOwner->Shape();
1793 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1794 if (aShapeType == TopAbs_VERTEX) {
1795 std::pair<AttributePtr, int> aPntAttrIndex =
1796 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1797 if (aPntAttrIndex.first.get() != NULL &&
1798 aSelectedAttributes.find(aPntAttrIndex.first) != aSelectedAttributes.end())
1799 theOwnersToSelect.Add(anOwner);
1800 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1801 theOwnersToSelect.Add(anOwner);
1804 else if (aShapeType == TopAbs_EDGE) {
1805 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1806 // try to restore local selection on Shape result
1807 // we can do this only if the shape was not changed
1808 theOwnersToSelect.Add(anOwner);
1809 aFoundLocalShape = true;
1814 if (!aFoundLocalShape) {
1815 // result owners are put in the list of selection only if local selected shapes were not
1817 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1818 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1819 Handle(StdSelect_BRepOwner) anOwner =
1820 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1821 if (anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1823 // select whole result
1824 theOwnersToSelect.Add(anOwner);
1831 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1832 const bool isToConnect)
1834 //Temporary commented as we do not modify values in property panel
1836 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1837 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1838 //connect(theWidget, SIGNAL(afterValuesChanged()),
1839 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1840 connect(theWidget, SIGNAL(afterValuesChanged()),
1841 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1844 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1845 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1846 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1847 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1848 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1849 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1853 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1855 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1856 (getCurrentOperation());
1858 if ((PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1859 isNestedSketchOperation(aFOperation)) &&
1860 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1861 FeaturePtr aFeature = aFOperation->feature();
1862 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1867 //void PartSet_SketcherMgr::customisePresentation(const ObjectPtr& theObject)
1869 // ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1870 // (getCurrentOperation());
1871 // if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1872 // isNestedSketchOperation(aFOperation)))
1873 // SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1875 // // update entities selection priorities
1876 // FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1877 // if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1878 // // update priority for feature
1879 // updateSelectionPriority(aFeature, aFeature);
1880 // // update priority for results of the feature
1881 // std::list<ResultPtr> aResults = aFeature->results();
1882 // std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1883 // for (; anIt != aLastIt; anIt++)
1884 // updateSelectionPriority(*anIt, aFeature);
1888 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1890 return myModule->workshop()->currentOperation();
1893 //**************************************************************
1894 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1896 ModuleBase_ModelWidget* aWidget = 0;
1897 ModuleBase_Operation* anOperation = getCurrentOperation();
1899 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1901 aWidget = aPanel->activeWidget();
1906 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1907 const bool isEditOperation,
1908 const bool isToDisplay,
1909 const bool isFlushRedisplay)
1911 #ifdef DEBUG_DO_NOT_BY_ENTER
1915 if (isEditOperation || !theFeature.get())
1918 // 1. change visibility of the object itself, here the presentable object is processed,
1919 // e.g. constraints features
1920 //FeaturePtr aFeature = aFOperation->feature();
1921 std::list<ResultPtr> aResults = theFeature->results();
1923 theFeature->setDisplayed(true);
1925 theFeature->setDisplayed(false);
1927 // change visibility of the object results, e.g. non-constraint features
1928 std::list<ResultPtr>::const_iterator aIt;
1929 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1931 (*aIt)->setDisplayed(true);
1934 (*aIt)->setDisplayed(false);
1937 if (isFlushRedisplay)
1938 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1941 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1942 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1944 if (!myCurrentSketch.get())
1947 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1948 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1949 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1951 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1952 aStoredPrs = aSelect->getHighlighted();
1954 QList<FeaturePtr> aFeatureList;
1955 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1956 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1957 ModuleBase_ISelection::AllControls);
1958 aStoredPrs.append(aSelected);
1961 // 1. it is necessary to save current selection in order to restore it after the features moving
1962 theCurrentSelection.clear();
1964 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1965 aLast = aStoredPrs.end();
1967 CompositeFeaturePtr aSketch = activeSketch();
1968 for (; anIt != aLast; anIt++) {
1969 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1970 ObjectPtr anObject = aPrs->object();
1971 if (!anObject.get())
1974 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1975 FeaturePtr aFeature;
1977 aFeature = ModelAPI_Feature::feature(aResult);
1979 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1981 if (!aFeature.get())
1984 std::set<AttributePtr> aSelectedAttributes;
1985 std::set<ResultPtr> aSelectedResults;
1986 SelectionInfo anInfo;
1987 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1988 anInfo = theCurrentSelection.find(aFeature).value();
1990 TopoDS_Shape aFirstShape;
1991 ResultPtr aFirstResult = aFeature->firstResult();
1992 if (aFirstResult.get() && aFirstResult->shape().get())
1993 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1994 anInfo.myFirstResultShape = aFirstShape;
1995 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1996 if (aResult.get()) {
1997 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1998 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
2001 std::list<ResultPtr> aResults = aFeature->results();
2002 std::list<ResultPtr>::const_iterator aIt;
2003 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
2004 ResultPtr aCurResult = *aIt;
2005 getAttributesOrResults(anOwner, aFeature, aSketch, aCurResult,
2006 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
2009 theCurrentSelection[aFeature] = anInfo;
2011 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
2014 void PartSet_SketcherMgr::restoreSelection(
2015 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
2017 if (!myCurrentSketch.get())
2020 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
2021 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2022 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
2023 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
2024 aSLast = theCurrentSelection.end();
2025 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
2026 anOwnersToSelect.Clear();
2027 for (; aSIt != aSLast; aSIt++) {
2028 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
2031 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
2034 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
2036 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
2038 updateBySketchParameters(aType, theState);
2039 myModule->workshop()->viewer()->update();
2042 void PartSet_SketcherMgr::updateBySketchParameters(
2043 const PartSet_Tools::ConstraintVisibleState& theType,
2046 if (myCurrentSketch.get() == NULL)
2049 bool aPrevState = myIsConstraintsShown[theType];
2050 myIsConstraintsShown[theType] = theState;
2053 case PartSet_Tools::Geometrical:
2054 case PartSet_Tools::Dimensional: {
2055 if (aPrevState != theState) {
2056 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
2057 for (int i = 0; i < aNumberOfSubs; i++) {
2058 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
2059 bool aProcessed = false;
2060 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
2062 aSubFeature->setDisplayed(aConstraintDisplayed);
2064 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2068 case PartSet_Tools::Expressions: {
2069 if (aPrevState != theState) {
2070 /// call all sketch features redisplay, the expression state will be corrected in customize
2071 /// of distance presentation
2072 SketcherPrs_Tools::ParameterStyle aStyle = myIsConstraintsShown[PartSet_Tools::Expressions]
2073 ? SketcherPrs_Tools::ParameterText : SketcherPrs_Tools::ParameterValue;
2074 SketcherPrs_Tools::setParameterStyle(aStyle);
2075 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2076 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
2080 default: // [to avoid compilation warning]
2085 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
2086 FeaturePtr theFeature)
2088 if (!theObject.get() || !theFeature.get())
2091 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
2092 Handle(AIS_InteractiveObject) anAISIO;
2093 if (anAIS.get() != NULL) {
2094 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
2097 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
2098 int anAdditionalPriority = 0;
2100 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2101 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
2102 if (aSPFeature.get() != NULL) {
2104 // 2. Simple segments
2105 // 3. External objects (violet color)
2106 // 4. Auxiliary segments (dotted)
2107 // StdSelect_BRepSelectionTool::Load uses priority calculating:
2108 // Standard_Integer aPriority =
2109 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
2110 // Priority of Vertex is 8, edge(segment) is 7.
2111 // It might be not corrected as provides the condition above.
2112 bool isExternal = aSPFeature->isExternal();
2113 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
2115 if (!isExternal && !isAuxiliary)
2116 anAdditionalPriority = 30;
2119 anAdditionalPriority = 20;
2120 // auxiliary feature
2122 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
2123 // edges/vertices of local selection on not-sketch objects
2125 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
2126 if (!aResult.IsNull()) {
2127 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
2133 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
2135 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
2136 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
2137 return aConnector->workshop();
2140 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
2142 return workshop()->operationMgr();
2145 void PartSet_SketcherMgr::onShowPoints(bool toShow)
2147 if (!myCurrentSketch.get())
2149 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2150 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
2151 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
2153 bool aToUpdate = false;
2155 std::list<ResultPtr> aFreePoints = SketcherPrs_Tools::getFreePoints(myCurrentSketch);
2157 // Delete obsolete presentations
2158 std::list<ResultPtr> aDelList;
2159 foreach(ResultPtr aObj, myPointsHighlight.keys()) {
2160 bool aFound = (std::find(aFreePoints.begin(), aFreePoints.end(), aObj) != aFreePoints.end());
2162 aDelList.push_back(aObj);
2164 foreach(ResultPtr aObj, aDelList) {
2165 aContext->Remove(myPointsHighlight[aObj], false);
2167 myPointsHighlight.remove(aObj);
2170 // Display new objects
2171 QList<ResultPtr> aKeysList = myPointsHighlight.keys();
2172 std::list<ResultPtr>::const_iterator aIt;
2173 for (aIt = aFreePoints.cbegin(); aIt != aFreePoints.cend(); aIt++) {
2174 if (!aKeysList.contains(*aIt)) {
2175 GeomShapePtr aShapePtr = (*aIt)->shape();
2176 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
2177 Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape);
2178 aShapePrs->SetColor(Quantity_NOC_BLUE1);
2179 aShapePrs->SetZLayer(Graphic3d_ZLayerId_Top);
2180 Handle(Prs3d_Drawer) aDrawer = aShapePrs->Attributes();
2181 if (aDrawer->HasOwnPointAspect()) {
2182 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
2183 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
2184 aDrawer->PointAspect()->SetScale(2);
2187 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2));
2188 aContext->Display(aShapePrs, false);
2189 aContext->Deactivate(aShapePrs);
2190 myPointsHighlight[*aIt] = aShapePrs;
2196 foreach(Handle(AIS_Shape) aPrs, myPointsHighlight.values()) {
2197 aContext->Remove(aPrs, false);
2200 myPointsHighlight.clear();
2206 void PartSet_SketcherMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
2208 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOF_OBJECTS)) {
2209 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
2210 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
2211 std::set<ObjectPtr> aObjects = anUpdateMsg->objects();
2212 std::set<ObjectPtr>::const_iterator aIt;
2213 QList<ModuleBase_ViewerPrsPtr> aPrsList;
2214 for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
2215 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aIt);
2216 if (aFeature.get()) {
2217 std::list<ResultPtr> aRes = aFeature->results();
2218 std::list<ResultPtr>::const_iterator aRIt;
2219 for (aRIt = aRes.cbegin(); aRIt != aRes.cend(); ++aRIt) {
2220 ModuleBase_ViewerPrsPtr aPrsPtr(new ModuleBase_ViewerPrs(*aRIt));
2221 aPrsList.append(aPrsPtr);
2225 if (aPrsList.size() > 0) {
2226 myModule->workshop()->setSelected(aPrsList);
2231 bool isExternal(const ObjectPtr& theObject)
2233 AttributeSelectionPtr aAttr =
2234 theObject->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
2236 return aAttr->context().get() != NULL && !aAttr->isInvalid();
2240 bool isCopy(const ObjectPtr& theObject)
2242 AttributeBooleanPtr anAttr = theObject->data()->boolean(SketchPlugin_SketchEntity::COPY_ID());
2244 return anAttr->value();
2248 bool isIncludeToResult(const ObjectPtr& theObject)
2250 AttributeBooleanPtr anAttr;
2251 std::set<AttributePtr> aRefsToMe = theObject->data()->refsToMe();
2252 std::set<AttributePtr>::const_iterator aIt;
2253 for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) {
2254 if ((*aIt)->id() == SketchPlugin_Projection::PROJECTED_FEATURE_ID()) {
2255 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aIt)->owner());
2256 if (aFeature.get() && !aFeature->isMacro()) {
2257 anAttr = aFeature->data()->boolean(SketchPlugin_Projection::INCLUDE_INTO_RESULT());
2259 return anAttr->value();
2266 //**************************************************************************************
2267 std::vector<int> PartSet_SketcherMgr::colorOfObject(const ObjectPtr& theObject,
2268 const FeaturePtr& theFeature, bool isConstruction) const
2270 PartSet_OverconstraintListener* aOCListener = myModule->overconstraintListener();
2271 std::string aKind = theFeature->getKind();
2273 if (aOCListener->isConflictingObject(theObject)) {
2274 return Config_PropManager::color("Visualization", "sketch_overconstraint_color");
2276 if (isDistanceKind(aKind)) {
2277 return Config_PropManager::color("Visualization", "sketch_dimension_color");
2279 if (isExternal(theFeature))
2280 return Config_PropManager::color("Visualization", "sketch_external_color");
2282 if (aOCListener->isFullyConstrained()) {
2283 return Config_PropManager::color("Visualization", "sketch_fully_constrained_color");
2285 if (aKind == SketchPlugin_ConstraintCoincidence::ID())
2286 return std::vector<int>(3, 0);
2289 return Config_PropManager::color("Visualization", "sketch_auxiliary_color");
2291 return Config_PropManager::color("Visualization", "sketch_entity_color");
2294 //**************************************************************************************
2295 void PartSet_SketcherMgr::customizeSketchPresentation(const ObjectPtr& theObject,
2296 const AISObjectPtr& thePrs) const
2298 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
2300 // set color from preferences
2301 std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
2302 aFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
2303 bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
2305 std::vector<int> aColor = colorOfObject(theObject, aFeature, isConstruction);
2306 if (!aColor.empty()) {
2307 // The code below causes redisplay again
2308 if (ModelAPI_Session::get()->isOperation()) {
2309 AttributeIntArrayPtr aColorAttr = theObject->data()->intArray(ModelAPI_Result::COLOR_ID());
2310 if (aColorAttr.get()) {
2311 aColorAttr->setSize(3, false);
2312 // Set the color attribute in order do not use default colors in the presentation object
2313 for (int i = 0; i < 3; i++)
2314 aColorAttr->setValue(i, aColor[i], false);
2317 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
2320 int aShapeType = thePrs->getShapeType();
2321 // a compound is processed like the edge because the
2322 // arc feature uses the compound for presentable AIS
2323 if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
2326 int aWidth = Config_PropManager::integer("Visualization", "sketch_line_width");
2327 if (isExternal(aFeature)) {
2328 thePrs->setWidth(isIncludeToResult(aFeature)? aWidth : 1);
2331 std::string aKind = aFeature->getKind();
2332 if (isDistanceKind(aKind))
2335 if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
2336 if (isConstruction) {
2337 // Set axilliary line
2338 thePrs->setWidth(SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY());
2339 thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY());
2342 thePrs->setWidth(aWidth);
2343 thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE());
2346 else if (aShapeType == 7) { // otherwise this is a vertex
2347 // The width value do not have effect on the point presentation.
2348 // It is defined in order to extend selection area of the object.
2349 thePrs->setWidth(17);
2350 // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
2352 if (isCopy(aFeature) || !isIncludeToResult(aFeature)) {
2353 double aPrsWidth = thePrs->width();
2354 thePrs->setWidth(aPrsWidth / 2.5);
2357 double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
2358 thePrs->setDeflection(aDeflection);
2361 //*************************************************************************************
2362 void PartSet_Fitter::fitAll(Handle(V3d_View) theView)
2364 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
2366 ModuleBase_IWorkshop* aWorkshop = mySketchMgr->module()->workshop();
2367 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
2368 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
2371 int aNumberOfSubs = aSketch->numberOfSubs();
2372 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2373 for (int i = 0; i < aNumberOfSubs; i++) {
2374 FeaturePtr aFeature = aSketch->subFeature(i);
2375 if (aDisplayer->isVisible(aFeature)) {
2376 AISObjectPtr aAisPtr = aDisplayer->getAISObject(aFeature);
2377 Handle(AIS_InteractiveObject) aAisObj = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2378 if (!aAisObj->IsInfinite()) {
2380 aAisObj->BoundingBox(aBox);
2385 std::list<ResultPtr> aResults = aFeature->results();
2386 std::list<ResultPtr>::const_iterator aIt;
2388 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
2390 if (aRes->isDisplayed()) {
2391 FeaturePtr aCurFeature = ModelAPI_Feature::feature(aRes);
2392 if (aCurFeature.get()) {
2393 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2394 std::dynamic_pointer_cast<SketchPlugin_Feature>(aCurFeature);
2395 if (aSPFeature.get()) {
2397 aSPFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
2398 if (!(aSPFeature->isExternal() || isAxiliary)) {
2399 GeomShapePtr aShape = aRes->shape();
2400 aShape->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2402 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2411 if (aBndBox.IsVoid())
2414 theView->FitAll(aBndBox, 0.01);