From 10ce2de039af32bddace50d895ce7b46f610dd12 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 21 Jul 2014 13:04:50 +0400 Subject: [PATCH] Make sketch features invisible in constructions and fix the nested commit warning --- src/Model/Model_Document.cpp | 7 +++++ src/Model/Model_ResultConstruction.cpp | 10 +++---- src/Model/Model_ResultConstruction.h | 9 ++++-- src/ModelAPI/ModelAPI_ResultConstruction.h | 3 ++ src/SketchPlugin/SketchPlugin_Arc.cpp | 34 +++++++++++++++------- src/SketchPlugin/SketchPlugin_Circle.cpp | 16 ++++++---- src/SketchPlugin/SketchPlugin_Line.cpp | 19 ++++++++---- src/SketchPlugin/SketchPlugin_Point.cpp | 10 +++++-- 8 files changed, 76 insertions(+), 32 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 30bd5e293..4ca962723 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -222,10 +222,17 @@ void Model_Document::compactNested() { void Model_Document::finishOperation() { // just to be sure that everybody knows that changes were performed + + if (!myDoc->HasOpenCommand() && myNestedNum != -1) + boost::static_pointer_cast(Model_PluginManager::get())-> + setCheckTransactions(false); // for nested transaction commit Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); + if (!myDoc->HasOpenCommand() && myNestedNum != -1) + boost::static_pointer_cast(Model_PluginManager::get())-> + setCheckTransactions(true); // for nested transaction commit if (myNestedNum != -1) // this nested transaction is owervritten myNestedNum++; diff --git a/src/Model/Model_ResultConstruction.cpp b/src/Model/Model_ResultConstruction.cpp index 8d230ab37..0b6d56612 100644 --- a/src/Model/Model_ResultConstruction.cpp +++ b/src/Model/Model_ResultConstruction.cpp @@ -14,12 +14,12 @@ boost::shared_ptr& Model_ResultConstruction::shape() return myShape; } -/* -boost::shared_ptr Model_ResultConstruction::owner() +Model_ResultConstruction::Model_ResultConstruction() { - return myOwner; -}*/ + myIsInHistory = true; +} -Model_ResultConstruction::Model_ResultConstruction() +void Model_ResultConstruction::setIsInHistory(const bool isInHistory) { + myIsInHistory = isInHistory; } diff --git a/src/Model/Model_ResultConstruction.h b/src/Model/Model_ResultConstruction.h index e312f6fda..fd04f2f7c 100644 --- a/src/Model/Model_ResultConstruction.h +++ b/src/Model/Model_ResultConstruction.h @@ -19,13 +19,18 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction { boost::shared_ptr myOwner; ///< owner of this result boost::shared_ptr myShape; ///< shape of this result created "on the fly" + bool myIsInHistory; public: + /// By default object is displayed in the object browser. + MODEL_EXPORT virtual bool isInHistory() {return myIsInHistory;} + /// Sets the result MODEL_EXPORT virtual void setShape(boost::shared_ptr theShape); /// Returns the shape-result produced by this feature MODEL_EXPORT virtual boost::shared_ptr& shape(); - /// Returns the source feature of this result - //MODEL_EXPORT virtual boost::shared_ptr owner(); + + /// Sets the flag that it must be displayed in history (default is true) + MODEL_EXPORT virtual void setIsInHistory(const bool myIsInHistory); protected: /// Makes a body on the given feature diff --git a/src/ModelAPI/ModelAPI_ResultConstruction.h b/src/ModelAPI/ModelAPI_ResultConstruction.h index bd9220ae5..231476e3c 100644 --- a/src/ModelAPI/ModelAPI_ResultConstruction.h +++ b/src/ModelAPI/ModelAPI_ResultConstruction.h @@ -34,6 +34,9 @@ public: /// Sets the result virtual void setShape(boost::shared_ptr theShape) = 0; + + /// Sets the flag that it must be displayed in history (default is true) + virtual void setIsInHistory(const bool isInHistory) = 0; }; //! Pointer on feature object diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 1445df99b..d66b52dbe 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -37,19 +37,23 @@ void SketchPlugin_Arc::execute() // compute a circle point in 3D view boost::shared_ptr aCenterAttr = - boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Arc::CENTER_ID())); + boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Arc::CENTER_ID())); // compute the arc start point boost::shared_ptr aStartAttr = - boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Arc::START_ID())); + boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Arc::START_ID())); if (aCenterAttr->isInitialized() && aStartAttr->isInitialized()) { - boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); + boost::shared_ptr aCenter( + aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); // make a visible point boost::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); aShapes.push_back(aCenterPointShape); // make a visible circle boost::shared_ptr aNDir = - boost::dynamic_pointer_cast(aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + boost::dynamic_pointer_cast( + aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); if (aHasPlane) { boost::shared_ptr aNormal = aNDir->dir(); @@ -57,7 +61,8 @@ void SketchPlugin_Arc::execute() // compute and change the arc end point boost::shared_ptr anEndAttr = - boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Arc::END_ID())); + boost::dynamic_pointer_cast(data()->attribute( + SketchPlugin_Arc::END_ID())); if (anEndAttr->isInitialized()) { boost::shared_ptr aCircleForArc( @@ -78,6 +83,7 @@ void SketchPlugin_Arc::execute() boost::shared_ptr aConstr = document()->createConstruction(data()); aConstr->setShape(aCompound); + aConstr->setIsInHistory(false); setResult(aConstr); } } @@ -90,15 +96,18 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::CENTER_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Arc::CENTER_ID())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::START_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Arc::START_ID())); aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY); boost::shared_ptr aPoint3 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::END_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Arc::END_ID())); aPoint3->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY); } @@ -108,17 +117,20 @@ double SketchPlugin_Arc::distanceToPoint(const boost::shared_ptr& boost::shared_ptr aData = data(); boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::CENTER_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Arc::CENTER_ID())); aDelta = aPoint1->pnt()->distance(thePoint); boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::START_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Arc::START_ID())); double aDistance = aPoint2->pnt()->distance(thePoint); if (aDelta < aDistance) aDelta = aDistance; boost::shared_ptr aPoint3 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::END_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Arc::END_ID())); aDistance = aPoint3->pnt()->distance(thePoint); if (aDelta < aDistance) aDelta = aDistance; diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 60fd29daf..35371ff9d 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -34,9 +34,11 @@ void SketchPlugin_Circle::execute() // compute a circle point in 3D view boost::shared_ptr aCenterAttr = - boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Circle::CENTER_ID())); + boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Circle::CENTER_ID())); AttributeDoublePtr aRadiusAttr = - boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Circle::RADIUS_ID())); + boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Circle::RADIUS_ID())); if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) { boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); // make a visible point @@ -45,7 +47,8 @@ void SketchPlugin_Circle::execute() // make a visible circle boost::shared_ptr aNDir = - boost::dynamic_pointer_cast(aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + boost::dynamic_pointer_cast(aSketch->data()->attribute( + SketchPlugin_Sketch::NORM_ID())); bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); if (aHasPlane) { boost::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); @@ -62,6 +65,7 @@ void SketchPlugin_Circle::execute() boost::shared_ptr aConstr = document()->createConstruction(data()); aConstr->setShape(aCompound); + aConstr->setIsInHistory(false); setResult(aConstr); } } @@ -73,7 +77,8 @@ void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Circle::CENTER_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Circle::CENTER_ID())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); } @@ -81,7 +86,8 @@ double SketchPlugin_Circle::distanceToPoint(const boost::shared_ptr aData = data(); boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Circle::CENTER_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Circle::CENTER_ID())); return aPoint->pnt()->distance(thePoint); } diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 63577ef08..1a44e2860 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -36,10 +36,12 @@ void SketchPlugin_Line::execute() if (aSketch) { // compute a start point in 3D view boost::shared_ptr aStartAttr = - boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Line::START_ID())); + boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Line::START_ID())); // compute an end point in 3D view boost::shared_ptr anEndAttr = - boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Line::END_ID())); + boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Line::END_ID())); if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) { boost::shared_ptr aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); boost::shared_ptr anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); @@ -49,6 +51,7 @@ void SketchPlugin_Line::execute() boost::shared_ptr aConstr = document()->createConstruction(data()); aConstr->setShape(anEdge); + aConstr->setIsInHistory(false); setResult(aConstr); } } @@ -61,11 +64,13 @@ void SketchPlugin_Line::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::START_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::START_ID())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::END_ID())); aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY); } @@ -75,9 +80,11 @@ double SketchPlugin_Line::distanceToPoint(const boost::shared_ptr boost::shared_ptr aData = data(); boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::START_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::START_ID())); boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::END_ID())); GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y()); diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index 5143b20a5..14efc4f6a 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -30,12 +30,14 @@ void SketchPlugin_Point::execute() if (aSketch) { // compute a point in 3D view boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Point::COORD_ID())); + boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Point::COORD_ID())); boost::shared_ptr aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y())); // make a visible point boost::shared_ptr aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D); boost::shared_ptr aConstr = document()->createConstruction(data()); aConstr->setShape(aPointShape); + aConstr->setIsInHistory(false); setResult(aConstr); } } @@ -47,7 +49,8 @@ void SketchPlugin_Point::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Point::COORD_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Point::COORD_ID())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); } @@ -55,7 +58,8 @@ double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr aData = data(); boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Point::COORD_ID())); + boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Point::COORD_ID())); return aPoint->pnt()->distance(thePoint); } -- 2.39.2