X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_SketcherMgr.cpp;h=207aee541f8eab4098baa9d5352f13d168db45f3;hb=c55b14977783111c8b418b416c7f6c2fa545c5e5;hp=30f1523b975c0a7b427234c22bf4dedde442742f;hpb=12385f8af09b5ffbdf68bb42124ef76f1d034957;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 30f1523b9..207aee541 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -9,12 +9,14 @@ #include "PartSet_WidgetPoint2d.h" #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_Tools.h" +#include "PartSet_WidgetSketchLabel.h" #include #include #include #include +#include #include #include #include @@ -47,18 +49,29 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include + +#include #include #include //#include -//#include +#include #include +#include #include #include +//#define DEBUG_DO_NOT_BY_ENTER /// Returns list of unique objects by sum of objects from List1 and List2 /*QList getSumList(const QList& theList1, @@ -114,7 +127,8 @@ void fillFeature2Attribute(const QList& theList, PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false), myIsPropertyPanelValueChanged(false), myIsMouseOverWindow(false), - myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true) + myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true), + myIsPopupMenuActive(false), myIsConstraintsShown(true) { ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); ModuleBase_IViewer* aViewer = anIWorkshop->viewer(); @@ -146,23 +160,36 @@ PartSet_SketcherMgr::~PartSet_SketcherMgr() void PartSet_SketcherMgr::onEnterViewPort() { - if (!isNestedCreateOperation(getCurrentOperation())) - return; // 1. if the mouse over window, update the next flag. Do not perform update visibility of // created feature because it should be done in onMouseMove(). Some widgets watch // the mouse move and use the cursor position to update own values. If the presentaion is // redisplayed before this update, the feature presentation jumps from reset value to current. myIsMouseOverWindow = true; myIsPropertyPanelValueChanged = false; + + #ifdef DEBUG_DO_NOT_BY_ENTER + return; + #endif + //if (!isNestedCreateOperation(getCurrentOperation())) + // return; } void PartSet_SketcherMgr::onLeaveViewPort() { - if (!isNestedCreateOperation(getCurrentOperation())) - return; - myIsMouseOverViewProcessed = false; myIsMouseOverWindow = false; + myIsPropertyPanelValueChanged = false; + + #ifdef DEBUG_DO_NOT_BY_ENTER + return; + #endif + + if (!isNestedCreateOperation(getCurrentOperation())) + return; + // the method should be performed if the popup menu is called, + // the reset of the current widget should not happen + if (myIsPopupMenuActive) + return; // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); @@ -180,10 +207,11 @@ void PartSet_SketcherMgr::onLeaveViewPort() aDisplayer->enableUpdateViewer(isEnableUpdateViewer); // hides the presentation of the current operation feature - myIsPropertyPanelValueChanged = false; + //myIsPropertyPanelValueChanged = false; // the feature is to be erased here, but it is correct to call canDisplayObject because // there can be additional check (e.g. editor widget in distance constraint) - visualizeFeature(aOperation, canDisplayObject()); + FeaturePtr aFeature = getCurrentOperation()->feature(); + visualizeFeature(aOperation, canDisplayObject(aFeature)); } void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel() @@ -227,7 +255,8 @@ void PartSet_SketcherMgr::onValuesChangedInPropertyPanel() ModuleBase_Operation* aOperation = getCurrentOperation(); // the feature is to be erased here, but it is correct to call canDisplayObject because // there can be additional check (e.g. editor widget in distance constraint) - visualizeFeature(aOperation, canDisplayObject()); + FeaturePtr aFeature = getCurrentOperation()->feature(); + visualizeFeature(aOperation, canDisplayObject(aFeature)); } void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) @@ -363,7 +392,8 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve } // the feature is to be erased here, but it is correct to call canDisplayObject because // there can be additional check (e.g. editor widget in distance constraint) - visualizeFeature(aOperation, canDisplayObject()); + FeaturePtr aFeature = getCurrentOperation()->feature(); + visualizeFeature(aOperation, canDisplayObject(aFeature)); } myClickedPoint.clear(); @@ -486,6 +516,10 @@ void PartSet_SketcherMgr::onApplicationStarted() XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer(); connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort())); connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort())); + + XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr(); + connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu())); + connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu())); } void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget) @@ -506,6 +540,16 @@ void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWid } } +void PartSet_SketcherMgr::onBeforeContextMenu() +{ + myIsPopupMenuActive = true; +} + +void PartSet_SketcherMgr::onAfterContextMenu() +{ + myIsPopupMenuActive = false; +} + void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, Point& thePoint) { @@ -518,18 +562,9 @@ void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent void PartSet_SketcherMgr::launchEditing() { - // there should be activate the vertex selection mode because the edit can happens by the selected - // point - QIntList aModes; - aModes << TopAbs_VERTEX << TopAbs_EDGE; - // TODO: #391 - to be uncommented - /*aModes.append(AIS_DSM_Text); - aModes.append(AIS_DSM_Line); - aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); - aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));*/ - - XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); - aConnector->activateSubShapesSelection(aModes); + // there should be activate the sketch selection mode because the edit can happens + // by any sketch entity or consttant selected + activateObjectsInSketchMode(true); if (!myCurrentSelection.empty()) { FeaturePtr aFeature = myCurrentSelection.begin().key(); @@ -543,7 +578,7 @@ void PartSet_SketcherMgr::launchEditing() } -QStringList PartSet_SketcherMgr::sketchOperationIdList() +const QStringList& PartSet_SketcherMgr::sketchOperationIdList() { static QStringList aIds; if (aIds.size() == 0) { @@ -557,10 +592,38 @@ QStringList PartSet_SketcherMgr::sketchOperationIdList() aIds << SketchPlugin_ConstraintRadius::ID().c_str(); aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str(); aIds << SketchPlugin_ConstraintParallel::ID().c_str(); + aIds << SketchPlugin_ConstraintHorizontal::ID().c_str(); + aIds << SketchPlugin_ConstraintVertical::ID().c_str(); + aIds << SketchPlugin_ConstraintEqual::ID().c_str(); + aIds << SketchPlugin_ConstraintTangent::ID().c_str(); + aIds << SketchPlugin_ConstraintCoincidence::ID().c_str(); + aIds << SketchPlugin_ConstraintFillet::ID().c_str(); + aIds << SketchPlugin_ConstraintMirror::ID().c_str(); + } + return aIds; +} + +const QStringList& PartSet_SketcherMgr::constraintsIdList() +{ + static QStringList aIds; + if (aIds.size() == 0) { + aIds << SketchPlugin_ConstraintLength::ID().c_str(); + aIds << SketchPlugin_ConstraintDistance::ID().c_str(); + aIds << SketchPlugin_ConstraintRigid::ID().c_str(); + aIds << SketchPlugin_ConstraintRadius::ID().c_str(); + aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str(); + aIds << SketchPlugin_ConstraintParallel::ID().c_str(); + aIds << SketchPlugin_ConstraintHorizontal::ID().c_str(); + aIds << SketchPlugin_ConstraintVertical::ID().c_str(); + aIds << SketchPlugin_ConstraintEqual::ID().c_str(); + aIds << SketchPlugin_ConstraintTangent::ID().c_str(); + aIds << SketchPlugin_ConstraintCoincidence::ID().c_str(); + aIds << SketchPlugin_ConstraintMirror::ID().c_str(); } return aIds; } + bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation) { return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID(); @@ -572,6 +635,21 @@ bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOpera PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id()); } +bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation) +{ + return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation); +} + +bool PartSet_SketcherMgr::isEntityOperation(ModuleBase_Operation* theOperation) +{ + std::string aId = theOperation ? theOperation->id().toStdString() : ""; + + return (aId == SketchPlugin_Line::ID()) || + (aId == SketchPlugin_Point::ID()) || + (aId == SketchPlugin_Arc::ID()) || + (aId == SketchPlugin_Circle::ID()); +} + bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) { std::string aId = theOperation ? theOperation->id().toStdString() : ""; @@ -622,6 +700,10 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) { myIsMouseOverWindow = false; + myIsConstraintsShown = true; + // the objects activated in the sketch should be deactivated in order to do not have the specific + // sketch selection mode activated on objects in neutral point of the application(no started operation) + activateObjectsInSketchMode(false); XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); @@ -665,22 +747,31 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) aDisplayer->updateViewer(); } -void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* ) +void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation) { + if (constraintsIdList().contains(theOperation->id())) { + // Show constraints if a constraint was created + onShowConstraintsToggle(true); + } connectToPropertyPanel(true); } -void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation) +void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) { connectToPropertyPanel(false); myIsPropertyPanelValueChanged = false; myIsMouseOverViewProcessed = true; + + // the sketch objects selection should be activated in order to select any sketch + // object + activateObjectsInSketchMode(true); } void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation) { if (isNestedCreateOperation(theOperation)) visualizeFeature(theOperation, true); + } bool PartSet_SketcherMgr::canUndo() const @@ -693,33 +784,63 @@ bool PartSet_SketcherMgr::canRedo() const return isNestedCreateOperation(getCurrentOperation()); } -bool PartSet_SketcherMgr::canDisplayObject() const +bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const { bool aCanDisplay = true; - if (!isNestedCreateOperation(getCurrentOperation())) - return aCanDisplay; - ModuleBase_Operation* aOperation = getCurrentOperation(); - ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); - ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0; - // the active widget editor should not influence here. The presentation should be visible always - // when this widget is active. - if (anActiveWdg) { - ModuleBase_WidgetEditor* anEditorWdg = dynamic_cast(anActiveWdg); - if (anEditorWdg) { - return aCanDisplay; + bool aHasActiveSketch = activeSketch().get() != NULL; + if (aHasActiveSketch) { + // 1. the sketch feature should not be displayed during the sketch active operation + // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch + // nested features can be visualized + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature.get() != NULL && aFeature == activeSketch()) + aCanDisplay = false; + } + else { // there are no an active sketch + // 2. sketch sub-features should not visualized if the sketch operation is not active + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature.get() != NULL) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aFeature); + if (aSketchFeature.get()) + aCanDisplay = false; } } - // during a nested create operation, the feature is redisplayed only if the mouse over view - // of there was a value modified in the property panel after the mouse left the view - aCanDisplay = myIsPropertyPanelValueChanged || myIsMouseOverWindow; + // 3. For created nested feature operation do not display the created feature if + // the mouse curstor leaves the OCC window. + // The correction cases, which ignores this condition: + // a. the property panel values modification + // b. the popup menu activated + // c. widget editor control + #ifndef DEBUG_DO_NOT_BY_ENTER + if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) { + ModuleBase_Operation* aOperation = getCurrentOperation(); + ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0; + ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast(anActiveWdg) : 0; + // the active widget editor should not influence here. The presentation should be visible always + // when this widget is active. + if (!anEditorWdg && !myIsPopupMenuActive) { + // during a nested create operation, the feature is redisplayed only if the mouse over view + // of there was a value modified in the property panel after the mouse left the view + aCanDisplay = myIsPropertyPanelValueChanged || myIsMouseOverWindow; + } + } + #endif return aCanDisplay; } + void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr& thePln) { myPlaneFilter->setPlane(thePln->impl()); + + // after the plane is selected in the sketch, the sketch selection should be activated + // it can not be performed in the sketch label widget because, we don't need to switch off + // the selection by any label deactivation, but need to switch it off by stop the sketch + activateObjectsInSketchMode(true); } void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature, @@ -877,14 +998,13 @@ ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const return myModule->workshop()->currentOperation(); } -bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation) const -{ - return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation); -} - void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay) { + #ifdef DEBUG_DO_NOT_BY_ENTER + return; + #endif + if (!theOperation || theOperation->isEditOperation()) return; @@ -914,10 +1034,26 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation, aDisplayer->updateViewer(); } -void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly) +void PartSet_SketcherMgr::activateObjectsInSketchMode(const bool isActive) { ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); + XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + QIntList aModes; + if (isActive) { + aModes.append(SketcherPrs_Tools::Sel_Dimension_Text); + aModes.append(SketcherPrs_Tools::Sel_Dimension_Line); + aModes.append(SketcherPrs_Tools::Sel_Constraint); + aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); + aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); + } + aDisplayer->activateObjects(aModes); +} + +void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly) +{ + ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); ModuleBase_ISelection* aSelect = aWorkshop->selection(); QList aHighlighted = aSelect->getHighlighted(); @@ -940,12 +1076,12 @@ void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly) FeaturePtr aFeature = anIt.key(); getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, myCurrentSelection); } - qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); + //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); } void PartSet_SketcherMgr::restoreSelection() { - qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); + //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(), @@ -958,3 +1094,29 @@ void PartSet_SketcherMgr::restoreSelection() aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false); } } + +void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn) +{ + if (myIsConstraintsShown == theOn) + return; + if (myCurrentSketch.get() == NULL) + return; + + myIsConstraintsShown = theOn; + + ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); + XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + const QStringList& aConstrIds = constraintsIdList(); + for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { + FeaturePtr aSubFeature = myCurrentSketch->subFeature(i); + if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) { + if (myIsConstraintsShown) + aDisplayer->display(aSubFeature, false); + else + aDisplayer->erase(aSubFeature, false); + } + } + aDisplayer->updateViewer(); +}