if (!anOriginal[i])
continue;
aSlvsEntities[i] = (Slvs_hEntity)anOriginal[i]->id();
+ // entity is not added into a storage, constraint can not be created
if (aSlvsEntities[i] == SLVS_E_UNKNOWN)
- return std::list<ConstraintWrapperPtr>(); // entity is not added into a storage, constraint can not be created
+ return std::list<ConstraintWrapperPtr>();
aConstrAttrList.push_back(anOriginal[i]);
}
std::list<ConstraintWrapperPtr> aResult;
std::list<EntityWrapperPtr> aConstrAttrList;
if (theEntity1->type() == ENTITY_POINT) {
- if (theEntity2->group() == theGroupID) // theEntity2 is not fixed
- makeMirrorPoints(theEntity1, theEntity2, theMirrorLine);
+ makeMirrorPoints(theEntity1, theEntity2, theMirrorLine);
aConstraint = Slvs_MakeConstraint(
SLVS_E_UNKNOWN, (Slvs_hGroup)theGroupID, SLVS_C_SYMMETRIC_LINE, (Slvs_hEntity)theSketchID,
aResult.insert(aResult.end(), aMrrList.begin(), aMrrList.end());
}
else if (theEntity1->type() == ENTITY_ARC) {
- // Do not allow mirrored arc recalculate its position until coordinated of all points recalculated
+ // Do not allow mirrored arc recalculate its position until
+ // coordinated of all points recalculated
FeaturePtr aMirrArc = theEntity2->baseFeature();
- aMirrArc->data()->blockSendAttributeUpdated(true);
+ bool aWasBlocked = aMirrArc->data()->blockSendAttributeUpdated(true);
std::list<ConstraintWrapperPtr> aMrrList;
std::list<EntityWrapperPtr>::const_iterator anIt1 = theEntity1->subEntities().begin();
std::list<EntityWrapperPtr>::const_iterator anIt2 = theEntity2->subEntities().begin();
- if ((*anIt2)->group() == theGroupID) // mirrored point is not fixed
- makeMirrorPoints(*anIt1, *anIt2, theMirrorLine);
+ makeMirrorPoints(*anIt1, *anIt2, theMirrorLine);
// Workaround to avoid problems in SolveSpace.
// The symmetry of two arcs will be done using symmetry of three points on these arcs:
anIt1 = aBaseArcPoints.begin();
anIt2 = aMirrorArcPoints.begin();
for (; anIt1 != aBaseArcPoints.end(); ++anIt1, ++anIt2) {
- aMrrList = createMirror(theConstraint, theGroupID, theSketchID, *anIt1, *anIt2, theMirrorLine);
+ aMrrList =
+ createMirror(theConstraint, theGroupID, theSketchID, *anIt1, *anIt2, theMirrorLine);
aResult.insert(aResult.end(), aMrrList.begin(), aMrrList.end());
}
// Restore event sending
- aMirrArc->data()->blockSendAttributeUpdated(false);
+ aMirrArc->data()->blockSendAttributeUpdated(aWasBlocked);
}
return aResult;
}
else if (aFeatureKind == SketchPlugin_Arc::ID())
return createArc(theFeature, theAttributes, theGroupID, theSketchID);
// Point (it has low probability to be an attribute of constraint, so it is checked at the end)
- else if (aFeatureKind == SketchPlugin_Point::ID() ||
+ else if (aFeatureKind == SketchPlugin_Point::ID() ||
aFeatureKind == SketchPlugin_IntersectionPoint::ID()) {
AttributePtr aPoint = theFeature->attribute(SketchPlugin_Point::COORD_ID());
if (!aPoint->isInitialized())
return aDummy;
- EntityWrapperPtr aSub = theAttributes.empty() ? createAttribute(aPoint, theGroupID, theSketchID) :
+ EntityWrapperPtr aSub = theAttributes.empty() ?
+ createAttribute(aPoint, theGroupID, theSketchID) :
theAttributes.front();
if (!aSub)
return aDummy;
std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
if (aPoint2D) {
- aParameters.push_back(createParameter(theGroupID, aPoint2D->x(), !aPoint2D->textX().empty()));
- aParameters.push_back(createParameter(theGroupID, aPoint2D->y(), !aPoint2D->textY().empty()));
+ aParameters.push_back(createParameter(theGroupID, aPoint2D->x(),
+ !aPoint2D->textX().empty()));
+ aParameters.push_back(createParameter(theGroupID, aPoint2D->y(),
+ !aPoint2D->textY().empty()));
// Create entity (parameters are not filled)
anEntity = Slvs_MakePoint2d(SLVS_E_UNKNOWN, (Slvs_hGroup)theGroupID,
(Slvs_hEntity)theSketchID, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
AttributeDoublePtr aScalar =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
if (aScalar) {
- aParameters.push_back(createParameter(theGroupID, aScalar->value(), !aScalar->text().empty()));
+ aParameters.push_back(createParameter(theGroupID, aScalar->value(),
+ !aScalar->text().empty()));
// Create entity (parameter is not filled)
anEntity = Slvs_MakeDistance(SLVS_E_UNKNOWN, (Slvs_hGroup)theGroupID,
(Slvs_hEntity)theSketchID, SLVS_E_UNKNOWN);
std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(theNormal);
std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(theDirX);
if (!aDirX || !aNorm ||
- (fabs(aDirX->x()) + fabs(aDirX->y()) + fabs(aDirX->z()) < tolerance) ||
+ (fabs(aDirX->x()) + fabs(aDirX->y()) + fabs(aDirX->z()) < tolerance) ||
!aNorm->isInitialized())
return EntityWrapperPtr();
// calculate Y direction
EntityWrapperPtr aStartEnt, aEndEnt;
std::list<EntityWrapperPtr>::const_iterator anIt = theAttributes.begin();
for (; anIt != theAttributes.end(); ++anIt) {
- std::shared_ptr<SolveSpaceSolver_EntityWrapper> aSlvsEntity =
+ std::shared_ptr<SolveSpaceSolver_EntityWrapper> aSlvsEntity =
std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(*anIt);
if (aSlvsEntity->isBase(aStart))
aStartEnt = aSlvsEntity;
EntityWrapperPtr aCenterEnt, aRadiusEnt, aNormalEnt;
std::list<EntityWrapperPtr>::const_iterator anIt = theAttributes.begin();
for (; anIt != theAttributes.end(); ++anIt) {
- std::shared_ptr<SolveSpaceSolver_EntityWrapper> aSlvsEntity =
+ std::shared_ptr<SolveSpaceSolver_EntityWrapper> aSlvsEntity =
std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(*anIt);
if (aSlvsEntity->isBase(aCenter))
aCenterEnt = aSlvsEntity;
EntityWrapperPtr aCenterEnt, aStartEnt, aEndEnt, aNormalEnt;
std::list<EntityWrapperPtr>::const_iterator anIt = theAttributes.begin();
for (; anIt != theAttributes.end(); ++anIt) {
- std::shared_ptr<SolveSpaceSolver_EntityWrapper> aSlvsEntity =
+ std::shared_ptr<SolveSpaceSolver_EntityWrapper> aSlvsEntity =
std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(*anIt);
if (aSlvsEntity->isBase(aCenter))
aCenterEnt = aSlvsEntity;
aConstraint->baseConstraint()->boolean(
SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->value()
};
- std::shared_ptr<GeomAPI_Angle2d> anAngle(new GeomAPI_Angle2d(aLine[0], isReversed[0], aLine[1], isReversed[1]));
+ std::shared_ptr<GeomAPI_Angle2d>
+ anAngle(new GeomAPI_Angle2d(aLine[0], isReversed[0], aLine[1], isReversed[1]));
std::shared_ptr<GeomAPI_Pnt2d> aCenter = anAngle->center();
- std::shared_ptr<GeomAPI_Dir2d> aDir[2];
-
Slvs_Constraint& aSlvsConstraint = aConstraint->changeConstraint();
- aSlvsConstraint.other = false;
- for (int i = 0; i < 2; i++) {
- aDir[i] = aLine[i]->direction();
- if (isReversed[i]) {
- aSlvsConstraint.other = !aSlvsConstraint.other;
- aDir[i]->reverse();
- }
- }
-
- double aDist[2][2];
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < 2; j++) {
- aDist[i][j] = aDir[i]->xy()->dot(aPoints[i][j]->xy()->decreased(aCenter->xy()));
- if (fabs(aDist[i][j]) <= tolerance)
- aDist[i][j] = 0.0;
- }
- }
-
- // Recalculate positions of lines to avoid conflicting constraints
- // while changing angle value several times
- double cosA = cos(aConstraint->value() * PI / 180.0);
- double sinA = sin(aConstraint->value() * PI / 180.0);
- //if (aDir[0]->cross(aDir[1]) < 0.0)
- // sinA *= -1.0;
- int aLineToUpd = 1;
- if (isFixed[1][0] && isFixed[1][1]) {
- sinA *= -1.0;
- aLineToUpd = 0;
- }
- double x = aDir[1-aLineToUpd]->x() * cosA - aDir[1-aLineToUpd]->y() * sinA;
- double y = aDir[1-aLineToUpd]->x() * sinA + aDir[1-aLineToUpd]->y() * cosA;
-
- std::shared_ptr<GeomAPI_Pnt2d> aNewPoints[2];
- for (int i = 0; i < 2; i++) {
- aNewPoints[i] = std::shared_ptr<GeomAPI_Pnt2d>(
- new GeomAPI_Pnt2d(aCenter->x() + x * aDist[aLineToUpd][i],
- aCenter->y() + y * aDist[aLineToUpd][i]));
- }
-
- std::shared_ptr<GeomAPI_XY> aDelta;
- if (isFixed[aLineToUpd][0] && !isFixed[aLineToUpd][1])
- aDelta = aPoints[aLineToUpd][0]->xy()->decreased(aNewPoints[0]->xy());
- else if (!isFixed[aLineToUpd][0] && isFixed[aLineToUpd][1])
- aDelta = aPoints[aLineToUpd][1]->xy()->decreased(aNewPoints[1]->xy());
- if (aDelta) {
- for (int i = 0; i < 2; i++) {
- aNewPoints[i]->setX(aNewPoints[i]->x() + aDelta->x());
- aNewPoints[i]->setY(aNewPoints[i]->y() + aDelta->y());
- }
- }
-
- // Update positions of points
- std::list<EntityWrapperPtr>::const_iterator anUpdLine = aConstrLines.begin();
- if (aLineToUpd > 0) ++anUpdLine;
- const std::list<EntityWrapperPtr>& anUpdPoints = (*anUpdLine)->subEntities();
- std::list<EntityWrapperPtr>::const_iterator aPIt = anUpdPoints.begin();
- for (int i = 0; aPIt != anUpdPoints.end(); ++aPIt, ++i) {
- std::shared_ptr<GeomDataAPI_Point2D> aPnt2D =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>((*aPIt)->baseAttribute());
- aPnt2D->setValue(aNewPoints[i]);
- }
+ aSlvsConstraint.other = isReversed[0] != isReversed[1];
}
void adjustMirror(ConstraintWrapperPtr theConstraint)
(*aMIt)->setValue(aCoord[i]);
// update corresponding attribute
- AttributePtr anAttr = std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(theMirrored)->baseAttribute();
+ AttributePtr anAttr =
+ std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(theMirrored)->baseAttribute();
if (anAttr) {
- std::shared_ptr<GeomDataAPI_Point2D> aMirroredPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
+ std::shared_ptr<GeomDataAPI_Point2D> aMirroredPnt =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
aMirroredPnt->setValue(aCoord[0], aCoord[1]);
}
}