From: nds Date: Fri, 30 May 2014 12:03:56 +0000 (+0400) Subject: #refs 77 - reported by Hervé Legrand: double click in 3D viewer leads to crash when... X-Git-Tag: V_0.4.4~336^2~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=47b355935ed9f269b46549816269fc03dc80f372;p=modules%2Fshaper.git #refs 77 - reported by Hervé Legrand: double click in 3D viewer leads to crash when create line The main functionality is in OperationSketchLine::onMouseRelease --- diff --git a/src/ModuleBase/ModuleBase_IOperation.cpp b/src/ModuleBase/ModuleBase_IOperation.cpp index 4e339672b..390cf96d2 100644 --- a/src/ModuleBase/ModuleBase_IOperation.cpp +++ b/src/ModuleBase/ModuleBase_IOperation.cpp @@ -74,6 +74,8 @@ void ModuleBase_IOperation::commit() document()->finishOperation(); emit stopped(); + + afterCommitOperation(); } void ModuleBase_IOperation::setRunning(bool theState) diff --git a/src/ModuleBase/ModuleBase_IOperation.h b/src/ModuleBase/ModuleBase_IOperation.h index b3373e4bf..ae10a849b 100644 --- a/src/ModuleBase/ModuleBase_IOperation.h +++ b/src/ModuleBase/ModuleBase_IOperation.h @@ -118,6 +118,9 @@ protected: virtual void abortOperation() = 0; /// Virtual method called when operation committed (see commit() method for more description) virtual void commitOperation() = 0; + /// Virtual method called after operation committed (see commit() method for more description) + /// it is important that the method is called after the stop() signal is emitted + virtual void afterCommitOperation() = 0; /// Returns pointer to the root document. boost::shared_ptr document() const; diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index c26eadb2a..8bf69185c 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -98,6 +98,10 @@ void ModuleBase_Operation::commitOperation() if (myFeature) myFeature->execute(); } +void ModuleBase_Operation::afterCommitOperation() +{ +} + void ModuleBase_Operation::flushUpdated() { Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index e66d58ab9..833dbf57c 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -80,6 +80,8 @@ protected: virtual void abortOperation(); /// Virtual method called when operation committed (see commit() method for more description) virtual void commitOperation(); + /// Virtual method called after operation committed (see commit() method for more description) + virtual void afterCommitOperation(); /// Send update message by loop void flushUpdated(); diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index d69aab8e0..fc034c739 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -108,7 +108,7 @@ void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_V emit setSelection(aSelected); } else if (aFeature) { - emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + restartOperation(PartSet_OperationEditLine::Type(), aFeature); } } } diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index f50dcb41d..3270705d6 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -85,7 +85,7 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie if (theHighlighted.size() == 1) { boost::shared_ptr aFeature = theHighlighted.front().feature(); if (aFeature) - emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + restartOperation(PartSet_OperationEditLine::Type(), aFeature); } else myFeatures = theHighlighted; @@ -101,7 +101,7 @@ void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) boost::shared_ptr aFeature = PartSet_Tools::NearestFeature(theEvent->pos(), theView, feature(), myFeatures); if (aFeature) - emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + restartOperation(PartSet_OperationEditLine::Type(), aFeature); } } diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 46b9a0541..c14ab9189 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -95,3 +95,9 @@ void PartSet_OperationSketchBase::keyReleased(std::string theName, QKeyEvent* th { keyReleased(theEvent->key()); } + +void PartSet_OperationSketchBase::restartOperation(const std::string& theType, + boost::shared_ptr theFeature) +{ + emit launchOperation(theType, theFeature); +} diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 4da9b9503..0c10c6c1a 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -94,6 +94,13 @@ public: virtual void keyReleased(std::string theName, QKeyEvent* theEvent); + /// Emits a signal about the operation start. This signal has an information about the feature. + /// If the provided feature is empty, the current operation feature is used. + /// \param theType a type of an operation started + /// theFeature the operation argument + void restartOperation(const std::string& theType, + boost::shared_ptr theFeature = boost::shared_ptr()); + signals: /// signal about the request to launch operation /// theName the operation name diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index ddd9bd728..fa16b1bf9 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -87,6 +87,15 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 const std::list& theSelected, const std::list& /*theHighlighted*/) { + if (myPointSelectionMode == SM_DonePoint) + { + // if the point creation is finished, the next mouse release should commit the modification + // the next release can happens by double click in the viewer + commit(); + restartOperation(PartSet_OperationSketchLine::Type(), feature()); + return; + } + double aX, anY; bool isFoundPoint = false; @@ -137,8 +146,6 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 } } } - //if (!isFoundPoint) - // return; switch (myPointSelectionMode) { @@ -187,8 +194,7 @@ void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_V case SM_DonePoint: { commit(); - emit featureConstructed(feature(), FM_Deactivation); - emit launchOperation(PartSet_OperationSketchLine::Type(), feature()); + restartOperation(PartSet_OperationSketchLine::Type(), feature()); } default: break; @@ -216,8 +222,7 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey) if (myPointSelectionMode == SM_DonePoint) { commit(); - emit featureConstructed(feature(), FM_Deactivation); - emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr()); + restartOperation(PartSet_OperationSketchLine::Type(), feature()); } //else // abort(); @@ -228,7 +233,6 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey) if (myPointSelectionMode == SM_DonePoint) { commit(); - emit featureConstructed(feature(), FM_Deactivation); } else abort(); @@ -258,6 +262,12 @@ void PartSet_OperationSketchLine::stopOperation() emit multiSelectionEnabled(true); } +void PartSet_OperationSketchLine::afterCommitOperation() +{ + PartSet_OperationSketchBase::afterCommitOperation(); + emit featureConstructed(feature(), FM_Deactivation); +} + boost::shared_ptr PartSet_OperationSketchLine::createFeature(const bool theFlushMessage) { boost::shared_ptr aNewFeature = ModuleBase_Operation::createFeature(false); @@ -320,8 +330,12 @@ void PartSet_OperationSketchLine::setConstraints(double theX, double theY) case SM_SecondPoint: aPointArg = LINE_ATTR_END; break; + default: + break; } + boost::shared_ptr aSkFeature = feature(); + boost::shared_ptr aData = feature()->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast (aData->attribute(aPointArg)); diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index d0c08e286..69a26936a 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -97,6 +97,9 @@ protected: /// Restore the multi selection state virtual void stopOperation(); + /// Virtual method called after operation committed (see commit() method for more description) + virtual void afterCommitOperation(); + /// Creates an operation new feature /// In addition to the default realization it appends the created line feature to /// the sketch feature