{
theValue.fillAttribute(theAttribute);
}
+void fillAttribute(int theValue,
+ const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute)
+{
+ theAttribute->setValue(theValue);
+}
//--------------------------------------------------------------------------------------
void fillAttribute(const ModelHighAPI_RefAttr & theValue,
void fillAttribute(const ModelHighAPI_Integer & theValue,
const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute);
+MODELHIGHAPI_EXPORT
+void fillAttribute(int theValue,
+ const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute);
+
MODELHIGHAPI_EXPORT
void fillAttribute(const ModelHighAPI_RefAttr & theValue,
const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute);
${PROJECT_SOURCE_DIR}/src/ModelAPI
${PROJECT_SOURCE_DIR}/src/GeomDataAPI
${PROJECT_SOURCE_DIR}/src/ModelHighAPI
+ ${PROJECT_SOURCE_DIR}/src/SketcherPrs
)
# Plugin headers dependency
#include <SketchPlugin_ConstraintTangent.h>
#include <SketchPlugin_ConstraintVertical.h>
+#include <SketcherPrs_Tools.h>
+
SketchAPI_Constraint::SketchAPI_Constraint(
const std::shared_ptr<ModelAPI_Feature> & theFeature)
: ModelHighAPI_Interface(theFeature)
return DUMMY;
}
+static std::string angleTypeToString(int theAngleType)
+{
+ switch (theAngleType) {
+ case SketcherPrs_Tools::ANGLE_COMPLEMENTARY:
+ return std::string("Complementary");
+ case SketcherPrs_Tools::ANGLE_BACKWARD:
+ return std::string("Backward");
+ default:
+ break;
+ }
+ return std::string();
+}
+
void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
{
ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(feature());
const std::string& aSetter = constraintTypeToSetter(aConstraint->getKind());
if (aSetter.empty())
return; // incorrect constraint type
+ bool isAngle = aConstraint->getKind() == SketchPlugin_ConstraintAngle::ID();
+ std::string aSetterSuffix;
+ if (isAngle)
+ aSetterSuffix = angleTypeToString(aConstraint->integer(
+ SketchPlugin_ConstraintAngle::TYPE_ID())->value());
const std::string& aSketchName = theDumper.parentName(aConstraint);
- theDumper << aConstraint << " = " << aSketchName << "." << aSetter << "(";
+ theDumper << aConstraint << " = " << aSketchName << "." << aSetter << aSetterSuffix << "(";
bool isFirstAttr = true;
for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
}
}
- AttributeDoublePtr aValueAttr = aConstraint->real(SketchPlugin_Constraint::VALUE());
+ AttributeDoublePtr aValueAttr = aConstraint->real(
+ isAngle ? SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() :SketchPlugin_Constraint::VALUE());
if (aValueAttr && aValueAttr->isInitialized())
theDumper << ", " << aValueAttr;
#include <SketchPlugin_ConstraintRigid.h>
#include <SketchPlugin_ConstraintTangent.h>
#include <SketchPlugin_ConstraintVertical.h>
+#include <SketcherPrs_Tools.h>
//--------------------------------------------------------------------------------------
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_ResultConstruction.h>
const ModelHighAPI_RefAttr & theLine2,
const ModelHighAPI_Double & theValue)
{
- // TODO(spo): is support of angle type necessary?
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
+ fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
+ aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
return aFeature;
}
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleComplementary(
+ const ModelHighAPI_RefAttr & theLine1,
+ const ModelHighAPI_RefAttr & theLine2,
+ const ModelHighAPI_Double & theValue)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
+ fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
+ aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
+ fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
+ fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
+ fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
+// fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
+ aFeature->execute();
+ return aFeature;
+}
+
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleBackward(
+ const ModelHighAPI_RefAttr & theLine1,
+ const ModelHighAPI_RefAttr & theLine2,
+ const ModelHighAPI_Double & theValue)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
+ fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
+ aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
+ fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
+ fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
+ fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
+// fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
+ aFeature->execute();
+ return aFeature;
+}
+
std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
const ModelHighAPI_RefAttr & thePoint1,
const ModelHighAPI_RefAttr & thePoint2)
const ModelHighAPI_RefAttr & theLine2,
const ModelHighAPI_Double & theValue);
+ /// Set complementary angle
+ SKETCHAPI_EXPORT
+ std::shared_ptr<ModelAPI_Feature> setAngleComplementary(
+ const ModelHighAPI_RefAttr & theLine1,
+ const ModelHighAPI_RefAttr & theLine2,
+ const ModelHighAPI_Double & theValue);
+
+ /// Set backward angle (= 360 - angle)
+ SKETCHAPI_EXPORT
+ std::shared_ptr<ModelAPI_Feature> setAngleBackward(
+ const ModelHighAPI_RefAttr & theLine1,
+ const ModelHighAPI_RefAttr & theLine2,
+ const ModelHighAPI_Double & theValue);
+
/// Set coincident
SKETCHAPI_EXPORT
std::shared_ptr<ModelAPI_Feature> setCoincident(
if (theID == SketchPlugin_Constraint::ENTITY_A() ||
theID == SketchPlugin_Constraint::ENTITY_B()) {
- std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
- if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
+ AttributeDoublePtr aValueAttr = real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID());
+ AttributeDoublePtr aConstrValueAttr = real(SketchPlugin_Constraint::VALUE());
+ // only if one of attributes is not initialized, try to compute the current value
+ if (!aValueAttr->isInitialized() || !aConstrValueAttr->isInitialized()) {
+ if (aValueAttr->isInitialized() && !aConstrValueAttr->isInitialized()) // initialize base value of constraint
+ updateConstraintValueByAngleValue();
double anAngle = calculateAngle();
aValueAttr->setValue(anAngle);
updateConstraintValueByAngleValue();