int anId = std::stoi(anIdStr);
// Check number of already registered objects of such kind. Index of current object
- // should be greater than it to identify feature's name as automatically generated.
- if (aNbFeatures < anId) {
+ // should be the same to identify feature's name as automatically generated.
+ if (aNbFeatures + 1 == anId) {
isUserDefined = false;
- aNbFeatures = anId - 1;
+ //aNbFeatures = anId - 1;
}
}
if (aFeatOwner.get() && !aFactory->isCase(aFeatOwner, theAttr->id())) {
return "__notcase__";
}
+ std::string aType = theAttr->attributeType();
+ std::ostringstream aResult;
if (!theAttr->isInitialized()) {
+ if (aType == ModelAPI_AttributeBoolean::typeId()) {
+ // special case for Boolean attribute (mean it false if not initialized)
+ aResult << false;
+ return aResult.str();
+ } else if (aType == ModelAPI_AttributeString::typeId()) {
+ // special case for attribute "SolverError"
+ if (theAttr->id() == "SolverError" &&
+ std::dynamic_pointer_cast<ModelAPI_Feature>(theAttr->owner())->getKind() == "Sketch")
+ return "";
+ }
+
return "__notinitialized__";
}
- std::string aType = theAttr->attributeType();
- std::ostringstream aResult;
if (aType == ModelAPI_AttributeDocRef::typeId()) {
AttributeDocRefPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDocRef>(theAttr);
DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
} else if (aType == ModelAPI_AttributeDouble::typeId()) {
AttributeDoublePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttr);
if (anAttr->text().empty())
- aResult<<anAttr->value();
+ aResult<<std::fixed<<setprecision(7)<<anAttr->value();
else
aResult<<anAttr->text();
} else if (aType == ModelAPI_AttributeBoolean::typeId()) {
INTERFACE_3(SketchPlugin_Projection::ID(),
externalFeature, SketchPlugin_Projection::EXTERNAL_FEATURE_ID(), ModelAPI_AttributeSelection, /** External feature */,
- projectedFeature, SketchPlugin_Projection::EXTERNAL_FEATURE_ID(), ModelAPI_AttributeRefAttr, /** Projected feature */,
+ projectedFeature, SketchPlugin_Projection::PROJECTED_FEATURE_ID(), ModelAPI_AttributeRefAttr, /** Projected feature */,
external, SketchPlugin_Projection::EXTERNAL_ID(), ModelAPI_AttributeSelection, /** External */
)
std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
{
std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
- LinePtr aLine(new SketchAPI_Line(aFeature, theExternal));
- setFixed(InterfacePtr(aLine));
- return aLine;
+ return LinePtr(new SketchAPI_Line(aFeature, theExternal));
}
std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
{
std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
- LinePtr aLine(new SketchAPI_Line(aFeature, theExternalName));
- setFixed(InterfacePtr(aLine));
- return aLine;
+ return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
}
//--------------------------------------------------------------------------------------
aCenterPnt->setValue(aCenterInSketch);
}
+ aProjection->boolean(COPY_ID())->setValue(true);
aProjection->execute();
aRefAttr->setObject(aProjection);
aSketchLineB = aSketchFeature.addFeature("SketchLine")
aStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
aEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
-aStartPoint.setValue(-20., 15.)
+aStartPoint.setValue(-10., 15.)
aEndPoint.setValue(80., 50.)
aSession.finishOperation()
#=========================================================================
refattrA.setObject(aSketchLineA.firstResult())
refattrB.setObject(aSketchLineB.firstResult())
anAngleVal.setValue(ANGLE_DEGREE)
+aConstraint.execute()
+aSession.finishOperation()
+aSession.startOperation()
aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt"))
aFlyoutPoint.setValue(50.0, 100.0)
-aConstraint.execute()
aSession.finishOperation()
+aSession.abortOperation()
assert (anAngleVal.isInitialized())
assert (refattrA.isInitialized())
assert (refattrB.isInitialized())
# A constraint to make equal radii of arc and external circle
#=========================================================================
aSession.startOperation()
-anExtCircRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchCircle_1"))
-assert(anExtCircRes)
-anExtCircShape = anExtCircRes.shape()
-assert(anExtCircShape)
anExtCircle = aSketchFeature.addFeature("SketchCircle")
anExtCircleCenter = geomDataAPI_Point2D(anExtCircle.attribute("CircleCenter"))
anExtCircleRadius = anExtCircle.real("CircleRadius")
anExtCircleCenter.setValue(-50., 50.)
anExtCircleRadius.setValue(10.)
-anExtCircle.selection("External").setValue(anExtCircRes, anExtCircShape)
+anExtCircle.selection("External").selectSubShape("EDGE", "Sketch_1/Edge-SketchCircle_1_2")
aSession.finishOperation()
aSession.startOperation()
aConstraintEqRad2 = aSketchFeature.addFeature("SketchConstraintEqual")
# A constraint to make equal length of line with external line
#=========================================================================
aSession.startOperation()
-anExtLineRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchLine_1"))
-assert(anExtLineRes)
-anExtLineShape = anExtLineRes.shape()
-assert(anExtLineShape)
anExtLine = aSketchFeature.addFeature("SketchLine")
anExtLineStart = geomDataAPI_Point2D(anExtLine.attribute("StartPoint"))
anExtLineEnd = geomDataAPI_Point2D(anExtLine.attribute("EndPoint"))
anExtLineStart.setValue(-40., 35.)
anExtLineEnd.setValue(-60., 25.)
-anExtLine.selection("External").setValue(anExtLineRes, anExtLineShape)
+anExtLine.selection("External").selectSubShape("EDGE", "Sketch_1/Edge-SketchLine_1")
anExtLineLen = lineLength(anExtLine)
aSession.finishOperation()
aSession.startOperation()
assert(anArc2StartPointNew == anArc2StartPointPrev)
assert(anArc2EndPointNew == anArc2EndPointPrev)
aSession.startOperation()
-aSketchFeature.removeFeature(aTangency)
+aDocument.removeFeature(aTangency)
aSession.finishOperation()
#=========================================================================
anArcPoints = []
aPoint = geomDataAPI_Point2D(aFilletArc.attribute("ArcStartPoint"))
- print "ArcStartPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
+ #print "ArcStartPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
anArcPoints.append((aPoint.x(), aPoint.y()))
aPoint = geomDataAPI_Point2D(aFilletArc.attribute("ArcEndPoint"))
- print "ArcEndPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
+ #print "ArcEndPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
anArcPoints.append((aPoint.x(), aPoint.y()))
aPoint = geomDataAPI_Point2D(aFilletArc.attribute("ArcCenter"))
- print "ArcCenter " + repr(aPoint.x()) + " " + repr(aPoint.y())
+ #print "ArcCenter " + repr(aPoint.x()) + " " + repr(aPoint.y())
aCenterX = aPoint.x()
aCenterY = aPoint.y()
aFilletRadius = math.hypot(anArcPoints[0][0]-aCenterX, anArcPoints[0][1]-aCenterY)
aLinePoints = []
aLinePoints.append((aStartPoint.x(), aStartPoint.y()))
- print "aLineStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
+ #print "aLineStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
aLinePoints.append((aEndPoint.x(), aEndPoint.y()))
- print "aLineEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
+ #print "aLineEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
aLineDirX = aEndPoint.x() - aStartPoint.x()
aLineDirY = aEndPoint.y() - aStartPoint.y()
aBaseArcPoints = []
aBaseArcPoints.append((aStartPoint.x(), aStartPoint.y()))
- print "anArcStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
+ #print "anArcStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
aBaseArcPoints.append((aEndPoint.x(), aEndPoint.y()))
- print "anArcEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
- print "anArcCenter " + repr(aCenterPoint.x()) + " " + repr(aCenterPoint.y())
+ #print "anArcEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
+ #print "anArcCenter " + repr(aCenterPoint.x()) + " " + repr(aCenterPoint.y())
aRadius = math.hypot(aStartPoint.x()-aCenterPoint.x(), aStartPoint.y()-aCenterPoint.y())
aDist = math.hypot(aCenterPoint.x() - aCenterX, aCenterPoint.y() - aCenterY)
anEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
aStartPoint.setValue(begin[0], begin[1])
anEndPoint.setValue(end[0], end[1])
+ aSketchLine.execute()
allStartPoints.append(aStartPoint)
allEndPoints.append(anEndPoint)
allLines.append(aSketchLine)
# Project all features onto the new sketch
#=========================================================================
aSession.startOperation()
-anExtLineRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchLine_1"))
-assert(anExtLineRes)
-anExtLineShape = anExtLineRes.shape()
-assert(anExtLineShape)
aLineProjector = aSketchFeature.addFeature("SketchProjection")
-aLineProjector.selection("ExternalFeature").setValue(anExtLineRes, anExtLineShape)
+aLineProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchLine_1")
aLineProjector.execute()
-anExtCircRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchCircle_1_2"))
-assert(anExtCircRes)
-anExtCircShape = anExtCircRes.shape()
-assert(anExtCircShape)
aCircleProjector = aSketchFeature.addFeature("SketchProjection")
-aCircleProjector.selection("ExternalFeature").setValue(anExtCircRes, anExtCircShape)
+aCircleProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchCircle_1_2")
aCircleProjector.execute()
-anExtArcRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchArc_1_2"))
-assert(anExtArcRes)
-anExtArcShape = anExtArcRes.shape()
-assert(anExtArcShape)
anArcProjector = aSketchFeature.addFeature("SketchProjection")
-anArcProjector.selection("ExternalFeature").setValue(anExtArcRes, anExtArcShape)
+anArcProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchArc_1_2")
anArcProjector.execute()
aSession.finishOperation()
#=========================================================================