From: vsv Date: Mon, 1 Dec 2014 17:22:23 +0000 (+0300) Subject: Editing lines by points dragging X-Git-Tag: V_0.6.0^2~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d8812a37a69beb9508879849782de6ed3f14e5e;p=modules%2Fshaper.git Editing lines by points dragging --- diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h index 00ff516b8..393137e5b 100644 --- a/src/ModuleBase/ModuleBase_IPropertyPanel.h +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.h @@ -19,7 +19,7 @@ class MODULEBASE_EXPORT ModuleBase_IPropertyPanel : public QDockWidget { Q_OBJECT public: - ModuleBase_IPropertyPanel(QWidget* theParent) : QDockWidget(theParent) {} + ModuleBase_IPropertyPanel(QWidget* theParent) : QDockWidget(theParent), myIsEditing(false) {} /// Returns currently active widget virtual ModuleBase_ModelWidget* activeWidget() const = 0; @@ -27,6 +27,10 @@ public: /// Returns all property panel's widget created by WidgetFactory virtual const QList& modelWidgets() const = 0; + /// Editing mode depends on mode of current operation. This value is defined by it. + void setEditingMode(bool isEditing) { myIsEditing = isEditing; } + bool isEditingMode() const { return myIsEditing; } + signals: /// The signal about key release on the control, that corresponds to the attribute /// \param theEvent key release event @@ -51,6 +55,9 @@ public slots: // highlighting from the previous active widget // emits widgetActivated(theWidget) signal virtual void activateWidget(ModuleBase_ModelWidget* theWidget) = 0; + +protected: + bool myIsEditing; }; #endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index b88becde9..0d00b7c3b 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -270,18 +270,6 @@ bool ModuleBase_Operation::activateByPreselection() return true; } } - - //ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - //if ((myPreSelection.size() > 0) && aActiveWgt) { - // const ModuleBase_ViewerPrs& aPrs = myPreSelection.first(); - // ModuleBase_WidgetValueFeature aValue; - // aValue.setObject(aPrs.object()); - // if (aActiveWgt->setValue(&aValue)) { - // myPreSelection.removeOne(aPrs); - // myPropertyPanel->activateNextWidget(); - // } - // // If preselection is enough to make a valid feature - apply it immediately - //} return false; } @@ -364,6 +352,7 @@ void ModuleBase_Operation::clearPreselection() void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) { myPropertyPanel = theProp; + myPropertyPanel->setEditingMode(isEditOperation()); //connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this, // SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); if (myPropertyPanel) { diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index ba997dcd3..93f886f13 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -48,7 +48,12 @@ #include #include + #include +#include +#include +#include +#include #include #include @@ -214,9 +219,10 @@ void PartSet_Module::onPlaneSelected(const std::shared_ptr& thePln) void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) { + ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel(); // Restart last operation type if ((theOperation->id() == myLastOperationId) && myLastFeature) { - ModuleBase_ModelWidget* aWgt = theOperation->propertyPanel()->activeWidget(); + ModuleBase_ModelWidget* aWgt = aPanel->activeWidget(); if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) { // Initialise new line with first point equal to end of previous PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast(aWgt); @@ -236,19 +242,20 @@ void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) // Start editing constraint if (theOperation->isEditOperation()) { std::string aId = theOperation->id().toStdString(); - if ((aId == SketchPlugin_ConstraintRadius::ID()) || - (aId == SketchPlugin_ConstraintLength::ID()) || - (aId == SketchPlugin_ConstraintDistance::ID())) { - ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel(); - // Find and activate widget for management of point for dimension line position - QList aWidgets = aPanel->modelWidgets(); - foreach (ModuleBase_ModelWidget* aWgt, aWidgets) { - PartSet_WidgetPoint2D* aPntWgt = dynamic_cast(aWgt); - if (aPntWgt) { - aPanel->activateWidget(aPntWgt); - return; + if (sketchOperationIdList().contains(QString(aId.c_str()))) { + if ((aId == SketchPlugin_ConstraintRadius::ID()) || + (aId == SketchPlugin_ConstraintLength::ID()) || + (aId == SketchPlugin_ConstraintDistance::ID())) { + // Find and activate widget for management of point for dimension line position + QList aWidgets = aPanel->modelWidgets(); + foreach (ModuleBase_ModelWidget* aWgt, aWidgets) { + PartSet_WidgetPoint2D* aPntWgt = dynamic_cast(aWgt); + if (aPntWgt) { + aPanel->activateWidget(aPntWgt); + return; + } } - } + } } } } @@ -275,7 +282,7 @@ void PartSet_Module::onSelectionChanged() } } -void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) +void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { if (!(theEvent->buttons() & Qt::LeftButton)) return; @@ -301,12 +308,23 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* // Remember highlighted objects for editing ModuleBase_ISelection* aSelect = myWorkshop->selection(); QList aObjects = aSelect->getHighlighted(); - myEditingFeatures.clear(); + myEditingFeatures.clear(); + myEditingAttr.clear(); if (aObjects.size() > 0) { foreach(ModuleBase_ViewerPrs aPrs, aObjects) { FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first().object()); - if (aFeature) + if (aFeature) { myEditingFeatures.append(aFeature); + TopoDS_Shape aShape = aPrs.shape(); + if (!aShape.IsNull()) { + if (aShape.ShapeType() == TopAbs_VERTEX) { + AttributePtr aAttr = PartSet_Tools::findAttributeBy2dPoint(myEditingFeatures.first(), + aShape, myCurrentSketch); + if (aAttr) + myEditingAttr.append(aAttr); + } + } + } } } // If nothing highlighted - return @@ -314,12 +332,6 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* return; if (isSketcher) { - CompositeFeaturePtr aSketch = - std::dynamic_pointer_cast(aOperation->feature()); - if (!PartSet_Tools::sketchPlane(aSketch)) - return; - - //myCurrentSketch = aOperation->feature(); myIsDragging = true; get2dPoint(theWnd, theEvent, myCurX, myCurY); myDragDone = false; @@ -328,6 +340,7 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* launchEditing(); } else if (isSketchOpe && isEditing) { + // If selected another object aOperation->abort(); myIsDragging = true; @@ -376,9 +389,9 @@ ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeat void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { + myWorkshop->viewer()->enableSelection(true); if (myIsDragging) { myIsDragging = false; - myWorkshop->viewer()->enableSelection(true); if (myDragDone) myWorkshop->currentOperation()->commit(); } @@ -400,22 +413,33 @@ void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* t double dX = aX - myCurX; double dY = aY - myCurY; - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(aOperation->feature()); - if (aSketchFeature) { - aSketchFeature->move(dX, dY); - ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - }/* else { // Alternative case for moving + if ((aOperation->id().toStdString() == SketchPlugin_Line::ID()) && + (myEditingAttr.size() > 0) && + myEditingAttr.first()) { + // probably we have prehighlighted point + AttributePtr aAttr = myEditingAttr.first(); + std::string aAttrId = aAttr->id(); ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); QList aWidgets = aPanel->modelWidgets(); - foreach(ModuleBase_ModelWidget* aWgt, aWidgets) { - PartSet_WidgetPoint2D* aWgt2d = dynamic_cast(aWgt); - if (aWgt2d) { - aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY); + // Find corresponded widget to provide dragging + foreach (ModuleBase_ModelWidget* aWgt, aWidgets) { + if (aWgt->attributeID() == aAttrId) { + PartSet_WidgetPoint2D* aWgt2d = dynamic_cast(aWgt); + if (aWgt2d) { + aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY); + break; + } } } - }*/ + } else { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aOperation->feature()); + if (aSketchFeature) { + aSketchFeature->move(dX, dY); + ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + } + } myDragDone = true; myCurX = aX; myCurY = aY; diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 305cd88e7..eb8fb5821 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -106,6 +107,7 @@ protected slots: double myCurX, myCurY; CompositeFeaturePtr myCurrentSketch; QList myEditingFeatures; + QList myEditingAttr; Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter; }; diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 04655869a..001224625 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -150,6 +150,11 @@ void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature) void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) { + // TO CHECK: Editing operation does not have automatical activation of widgets + if (isEditingMode()) { + activateWidget(NULL); + return; + } ModuleBase_ModelWidget* aNextWidget = 0; QList::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end(); bool isFoundWidget = false; @@ -210,6 +215,6 @@ void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget) myActiveWidget = theWidget; if (myActiveWidget) emit widgetActivated(theWidget); - else + else if (!isEditingMode()) emit noMoreWidgets(); } diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index 0fcd179b8..a2db13b1e 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -21,7 +21,8 @@ XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop) QList XGUI_Selection::getSelected(int theShapeTypeToSkip) const { - //std::set aPrsFeatures; + QList aSelectedIds; // Remember of selected address in order to avoid duplicates + QList aPresentations; XGUI_Displayer* aDisplayer = myWorkshop->displayer(); @@ -29,17 +30,16 @@ QList XGUI_Selection::getSelected(int theShapeTypeToSkip) if (aContext->HasOpenedContext()) { for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { ModuleBase_ViewerPrs aPrs; - Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); + if (aSelectedIds.contains((long)anIO.Access())) + continue; + + aSelectedIds.append((long)anIO.Access()); aPrs.setInteractive(anIO); ObjectPtr aFeature = aDisplayer->getObject(anIO); // we should not check the appearance of this feature because there can be some selected shapes // for one feature - //if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) { - aPrs.setFeature(aFeature); - //aPrsFeatures.insert(aFeature); - //} TopoDS_Shape aShape = aContext->SelectedShape(); if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip)) aPrs.setShape(aShape); @@ -50,17 +50,15 @@ QList XGUI_Selection::getSelected(int theShapeTypeToSkip) } else { for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) { ModuleBase_ViewerPrs aPrs; - Handle(AIS_InteractiveObject) anIO = aContext->Current(); + if (aSelectedIds.contains((long)anIO.Access())) + continue; + + aSelectedIds.append((long)anIO.Access()); aPrs.setInteractive(anIO); ObjectPtr aFeature = aDisplayer->getObject(anIO); - // we should not check the appearance of this feature because there can be some selected shapes - // for one feature - //if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) { aPrs.setFeature(aFeature); - //aPrsFeatures.insert(aFeature); - //} aPresentations.append(aPrs); } } @@ -69,7 +67,7 @@ QList XGUI_Selection::getSelected(int theShapeTypeToSkip) QList XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const { - //std::set aPrsFeatures; + QList aSelectedIds; // Remember of selected address in order to avoid duplicates QList aPresentations; XGUI_Displayer* aDisplayer = myWorkshop->displayer(); @@ -77,15 +75,16 @@ QList XGUI_Selection::getHighlighted(int theShapeTypeToSki for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { ModuleBase_ViewerPrs aPrs; Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive(); + if (aSelectedIds.contains((long)anIO.Access())) + continue; + + aSelectedIds.append((long)anIO.Access()); aPrs.setInteractive(anIO); ObjectPtr aResult = aDisplayer->getObject(anIO); // we should not check the appearance of this feature because there can be some selected shapes // for one feature - //if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) { - aPrs.setFeature(aResult); - //aPrsFeatures.insert(aResult); - //} + aPrs.setFeature(aResult); if (aContext->HasOpenedContext()) { TopoDS_Shape aShape = aContext->DetectedShape(); if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)