-Slvs_hEntity SketchSolver_Constraint::changeEntity(FeaturePtr theEntity, int& theType)
-{
- Slvs_hEntity aResult = SLVS_E_UNKNOWN;
- if (!theEntity->data() || !theEntity->data()->isValid())
- return SLVS_E_UNKNOWN;
- // If the entity is already in the group, try to find it
- std::map<FeaturePtr, Slvs_hEntity>::const_iterator anEntIter = myFeatureMap.find(theEntity);
- Slvs_Entity aCurrentEntity;
- aCurrentEntity.h = SLVS_E_UNKNOWN;
- if (anEntIter != myFeatureMap.end())
- aCurrentEntity = myStorage->getEntity(anEntIter->second);
- else {
- aResult = myGroup->getFeatureId(theEntity);
- if (aResult != SLVS_E_UNKNOWN) {
- Slvs_Entity anEnt = myStorage->getEntity(aResult);
- theType = anEnt.type;
- myFeatureMap[theEntity] = aResult;
- return aResult;
- }
- }
-
- Slvs_hGroup aGroupID = myGroup->getId();
- Slvs_hEntity aWorkplaneID = myGroup->getWorkplaneId();
- DataPtr aData = theEntity->data();
-
- // SketchPlugin features
- const std::string& aFeatureKind = theEntity->getKind();
- AttributePtr anAttribute;
- int anAttrType;
- // Line
- if (aFeatureKind == SketchPlugin_Line::ID()) {
- anAttribute = aData->attribute(SketchPlugin_Line::START_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aStart = changeEntity(anAttribute, anAttrType);
-
- anAttribute = aData->attribute(SketchPlugin_Line::END_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aEnd = changeEntity(anAttribute, anAttrType);
-
- if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity
- aCurrentEntity = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, aStart, aEnd);
- else {
- aCurrentEntity.point[0] = aStart;
- aCurrentEntity.point[1] = aEnd;
- }
- aResult = myStorage->addEntity(aCurrentEntity);
- }
- // Circle
- else if (aFeatureKind == SketchPlugin_Circle::ID()) {
- anAttribute = aData->attribute(SketchPlugin_Circle::CENTER_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aCenter = changeEntity(anAttribute, anAttrType);
-
- anAttribute = aData->attribute(SketchPlugin_Circle::RADIUS_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aRadius = changeEntity(anAttribute, anAttrType);
-
- if (aCurrentEntity.h == SLVS_E_UNKNOWN) { // New entity
- Slvs_Entity aWorkplane = myStorage->getEntity(aWorkplaneID);
- aCurrentEntity = Slvs_MakeCircle(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID,
- aCenter, aWorkplane.normal, aRadius);
- } else {
- aCurrentEntity.point[0] = aCenter;
- aCurrentEntity.distance = aRadius;
- }
- aResult = myStorage->addEntity(aCurrentEntity);
- }
- // Arc
- else if (aFeatureKind == SketchPlugin_Arc::ID()) {
- anAttribute = aData->attribute(SketchPlugin_Arc::CENTER_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aCenter = changeEntity(anAttribute, anAttrType);
-
- anAttribute = aData->attribute(SketchPlugin_Arc::START_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aStart = changeEntity(anAttribute, anAttrType);
-
- anAttribute = aData->attribute(SketchPlugin_Arc::END_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aEnd = changeEntity(anAttribute, anAttrType);
-
- if (aCurrentEntity.h == SLVS_E_UNKNOWN) { // New entity
- Slvs_Entity aWorkplane = myStorage->getEntity(aWorkplaneID);
- aCurrentEntity = Slvs_MakeArcOfCircle(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID,
- aWorkplane.normal, aCenter, aStart, aEnd);
- } else {
- aCurrentEntity.point[0] = aCenter;
- aCurrentEntity.point[1] = aStart;
- aCurrentEntity.point[2] = aEnd;
- }
- aResult = myStorage->addEntity(aCurrentEntity);
- }
- // Point (it has low probability to be an attribute of constraint, so it is checked at the end)
- else if (aFeatureKind == SketchPlugin_Point::ID()) {
- anAttribute = aData->attribute(SketchPlugin_Point::COORD_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- // Both the sketch point and its attribute (coordinates) link to the same SolveSpace point identifier
- aResult = changeEntity(anAttribute, anAttrType);
- aCurrentEntity.type = SLVS_E_POINT_IN_3D;
- }
-
- if (aResult != SLVS_E_UNKNOWN) {
- myFeatureMap[theEntity] = aResult;
- theType = aCurrentEntity.type;
- }
- return aResult;
-}
-
-std::list<ConstraintPtr> SketchSolver_Constraint::constraints() const
-{
- std::list<ConstraintPtr> aConstraints;
- aConstraints.push_back(myBaseConstraint);
- return aConstraints;