From 1b924118b0bae94721d1b1af799c8e37506ab7a4 Mon Sep 17 00:00:00 2001 From: sbh Date: Mon, 24 Nov 2014 14:39:43 +0300 Subject: [PATCH] Fixes in python code to avoid modifications outside of a transaction: # Implicit calls of startOperation/finishOperation removed # Method for "ConstraintLength" created inside of sketch API module # C++ API corrected to avoid hangs on modifications outside of a transaction --- src/Events/Events_Loop.cpp | 4 +++- src/PythonFeaturesPlugin/examples.py | 21 ++++++--------------- src/PythonFeaturesPlugin/sketch.py | 7 ++++++- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index eadae7283..189516ae0 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -122,7 +122,9 @@ void Events_Loop::flush(const Events_ID& theID) boost::shared_ptr aGroup = aMyGroup->second; myGroups.erase(aMyGroup); send(aGroup, false); - myFlushed.erase(myFlushed.find(theID.myID)); + std::set::iterator anIt = myFlushed.find(theID.myID); + if (anIt != myFlushed.end()) + myFlushed.erase(myFlushed.find(theID.myID)); } } diff --git a/src/PythonFeaturesPlugin/examples.py b/src/PythonFeaturesPlugin/examples.py index 75c5e7733..d2279de34 100644 --- a/src/PythonFeaturesPlugin/examples.py +++ b/src/PythonFeaturesPlugin/examples.py @@ -1,35 +1,28 @@ from ModelAPI import * +from SketchResult import * import sketch import extrusion -from SketchResult import * #reload(sketch) # Pour tester plus facilement #reload(extrusion) # Pour tester plus facilement def makeBox(aLength, aWidth, aHeight): - print "makeBox" # Getting the active document - session = ModelAPI_Session.get() part = session.activeDocument() - # Starting the Sketch - - session.startOperation() base = sketch.addTo(part) sketch.setXOYPlane(base) - # Creating the lines - - l1 = sketch.addLine(10, 10, 10, 50, base) - l2 = sketch.addLine(10, 50, 60, 60, base) - l3 = sketch.addLine(60, 60, 50, 10, base) - l4 = sketch.addLine(50, 10, 10, 10, base) + l1 = sketch.addLine(10, 10, 10, 50, base) + l2 = sketch.addLine(10, 50, 60, 60, base) + l3 = sketch.addLine(60, 60, 50, 10, base) + l4 = sketch.addLine(50, 10, 10, 10, base) + base.execute() # Creating the constraints - # NOTE : the following lines are currently not working in BR_PYTHON_PLUGIN branch """ sketch.makeCoincident(sketch.getEndPoint(l1), sketch.getStartPoint(l2), base) @@ -44,12 +37,10 @@ def makeBox(aLength, aWidth, aHeight): """ # Finalisation of the operation - builder = SketchResult(base) # Creating a feature Extrusion box = extrusion.addNew(builder, 50, part) - session.finishOperation() #return base.lastResult() return extrusion.getBody(box) diff --git a/src/PythonFeaturesPlugin/sketch.py b/src/PythonFeaturesPlugin/sketch.py index 462c1808a..6d002d307 100644 --- a/src/PythonFeaturesPlugin/sketch.py +++ b/src/PythonFeaturesPlugin/sketch.py @@ -82,7 +82,7 @@ def addLine(x1, y1, x2, y2, sketch): def getGeometry(line): - return line.firstResult() + return modelAPI_ResultConstruction(line.firstResult()) def getStartPoint(line): @@ -112,3 +112,8 @@ def makePerpendicular(l1, l2, sketch): constraint = sketch.addFeature("SketchConstraintPerpendicular") constraint.refattr("ConstraintEntityA").setObject(l1) constraint.refattr("ConstraintEntityB").setObject(l2) + +def makeConstantLength(line, length, sketch): + constraint = sketch.addFeature("SketchConstraintLength") + constraint.refattr("ConstraintEntityA").setObject(line) + constraint.real("ConstraintValue").setValue(length) -- 2.39.2