From: vsv Date: Tue, 2 Dec 2014 17:05:19 +0000 (+0300) Subject: Improve sketcher X-Git-Tag: V_0.6.0^2~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fff712ccf1829a0311fc192395be8788f71e4326;p=modules%2Fshaper.git Improve sketcher --- diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 0d00b7c3b..9f062b7ad 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -30,6 +30,8 @@ #include +#include + #ifdef _DEBUG #include #endif @@ -94,11 +96,11 @@ bool ModuleBase_Operation::canBeCommitted() const { return isValid(); } -// -//void ModuleBase_Operation::flushUpdated() -//{ -// Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); -//} + +void ModuleBase_Operation::flushUpdated() +{ + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); +} void ModuleBase_Operation::flushCreated() { @@ -260,8 +262,9 @@ bool ModuleBase_Operation::activateByPreselection() } if (isSet && canBeCommitted()) { // if all widgets are filled with selection - commit(); - return true; + bool aIsDone = commit(); + QApplication::processEvents(); + return aIsDone; } else { //activate next widget diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 208e35035..4a155ebe2 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -209,7 +209,7 @@ signals: virtual void afterCommitOperation() {} /// Send update message by loop - //void flushUpdated(); + void flushUpdated(); /// Send created message by loop void flushCreated(); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 490ffdfd9..39830ef55 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -69,6 +69,22 @@ #endif +/// Returns list of unique objects by sum of objects from List1 and List2 +QList getSumList(const QList& theList1, + const QList& theList2) +{ + QList aRes; + foreach (ModuleBase_ViewerPrs aPrs, theList1) { + if (!aRes.contains(aPrs.object())) + aRes.append(aPrs.object()); + } + foreach (ModuleBase_ViewerPrs aPrs, theList2) { + if (!aRes.contains(aPrs.object())) + aRes.append(aPrs.object()); + } + return aRes; +} + /*!Create and return new instance of XGUI_Module*/ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop) { @@ -286,6 +302,7 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* { if (!(theEvent->buttons() & Qt::LeftButton)) return; + ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); // Use only for sketch operations if (aOperation && myCurrentSketch) { @@ -305,14 +322,31 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* if ((!isSketcher) && (!isEditing)) return; + if (theEvent->modifiers()) { + // If user performs multiselection + if (isSketchOpe && (!isSketcher)) + if (!aOperation->commit()) + aOperation->abort(); + return; + } // Remember highlighted objects for editing ModuleBase_ISelection* aSelect = myWorkshop->selection(); - QList aObjects = aSelect->getHighlighted(); + QList aHighlighted = aSelect->getHighlighted(); + QList aSelected = aSelect->getSelected(); myEditingFeatures.clear(); myEditingAttr.clear(); - if (aObjects.size() == 1) { - foreach(ModuleBase_ViewerPrs aPrs, aObjects) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first().object()); + if ((aHighlighted.size() == 0) && (aSelected.size() == 0)) { + if (isSketchOpe && (!isSketcher)) + // commit previous operation + if (!aOperation->commit()) + aOperation->abort(); + return; + } + + if ((aHighlighted.size() == 1) && (aSelected.size() == 0)) { + // Move by selected shape (vertex). Can be used only for single selection + foreach(ModuleBase_ViewerPrs aPrs, aHighlighted) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aHighlighted.first().object()); if (aFeature) { myEditingFeatures.append(aFeature); TopoDS_Shape aShape = aPrs.shape(); @@ -326,7 +360,16 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* } } } - } + } else { + // Provide multi-selection. Can be used only for features + QList aObjects = getSumList(aHighlighted, aSelected); + foreach (ObjectPtr aObj, aObjects) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + if (aFeature && (!myEditingFeatures.contains(aFeature))) + myEditingFeatures.append(aFeature); + } + + } // If nothing highlighted - return if (myEditingFeatures.size() == 0) return; @@ -367,7 +410,7 @@ void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* the void PartSet_Module::launchEditing() { - if (myEditingFeatures.size() == 1) { + if (myEditingFeatures.size() > 0) { FeaturePtr aFeature = myEditingFeatures.first(); std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aFeature); @@ -392,8 +435,11 @@ void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent myWorkshop->viewer()->enableSelection(true); if (myIsDragging) { myIsDragging = false; - if (myDragDone) + if (myDragDone) { myWorkshop->currentOperation()->commit(); + myEditingFeatures.clear(); + myEditingAttr.clear(); + } } } @@ -414,7 +460,7 @@ void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* t double dY = aY - myCurY; if ((aOperation->id().toStdString() == SketchPlugin_Line::ID()) && - (myEditingAttr.size() > 0) && + (myEditingAttr.size() == 1) && myEditingAttr.first()) { // probably we have prehighlighted point AttributePtr aAttr = myEditingAttr.first(); @@ -432,14 +478,16 @@ void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* t } } } 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_MOVED)); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + foreach(FeaturePtr aFeature, myEditingFeatures) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aFeature); + if (aSketchFeature) { + aSketchFeature->move(dX, dY); + ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent); + } } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED)); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); } myDragDone = true; myCurX = aX;