TestFillet.py
TestRectangle.py
TestProjection.py
- #TestSplit.py
+ TestSplit.py
TestHighload.py
TestSnowflake.py)
#include "SketchPlugin_ConstraintSplit.h"
+#include <GeomAPI_Dir2d.h>
#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_XY.h>
#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeString.h>
#include <ModelGeomAlgo_Point2D.h>
#include <Events_Loop.h>
+#include <cmath>
+
#define DEBUG_SPLIT
#ifdef DEBUG_SPLIT
#include <iostream>
#endif
+static const double PI = 3.141592653589793238463;
+
SketchPlugin_ConstraintSplit::SketchPlugin_ConstraintSplit()
{
}
return;
}
- arrangePoints(aStartPointAttrOfBase, anEndPointAttrOfBase, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
+ arrangePointsOnLine(aStartPointAttrOfBase, anEndPointAttrOfBase, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
/// create a split feature
theSplitFeature = createLineFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
return;
}
- arrangePoints(aStartPointAttrOfBase, anEndPointAttrOfBase, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
+ arrangePointsOnArc(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase,
+ aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
/// split feature
theSplitFeature = createArcFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
theCreatedFeatures.insert(aConstraintFeature);
}
-void SketchPlugin_ConstraintSplit::arrangePoints(const AttributePoint2DPtr& theStartPointAttr,
- const AttributePoint2DPtr& theEndPointAttr,
- AttributePoint2DPtr& theFirstPointAttr,
- AttributePoint2DPtr& theLastPointAttr)
+void SketchPlugin_ConstraintSplit::arrangePointsOnLine(
+ const AttributePoint2DPtr& theStartPointAttr,
+ const AttributePoint2DPtr& theEndPointAttr,
+ AttributePoint2DPtr& theFirstPointAttr,
+ AttributePoint2DPtr& theLastPointAttr) const
{
- /// if first point is closer to last point, wrap first and last values
+ // if first point is closer to last point, swap first and last values
if (theStartPointAttr->pnt()->distance(theFirstPointAttr->pnt()) >
theStartPointAttr->pnt()->distance(theLastPointAttr->pnt())) {
AttributePoint2DPtr aTmpPoint = theFirstPointAttr;
}
}
+void SketchPlugin_ConstraintSplit::arrangePointsOnArc(
+ const FeaturePtr& theArc,
+ const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
+ const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
+ std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
+ std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const
+{
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theArc->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt();
+ bool isReversed = theArc->boolean(SketchPlugin_Arc::INVERSED_ID())->value();
+
+ // collect directions to each point
+ std::shared_ptr<GeomAPI_Dir2d> aStartDir(
+ new GeomAPI_Dir2d(theStartPointAttr->pnt()->xy()->decreased(aCenter->xy())));
+ std::shared_ptr<GeomAPI_Dir2d> aFirstPtDir(
+ new GeomAPI_Dir2d(theFirstPointAttr->pnt()->xy()->decreased(aCenter->xy())));
+ std::shared_ptr<GeomAPI_Dir2d> aSecondPtDir(
+ new GeomAPI_Dir2d(theSecondPointAttr->pnt()->xy()->decreased(aCenter->xy())));
+
+ // sort points by their angular values
+ double aFirstPtAngle = aStartDir->angle(aFirstPtDir);
+ double aSecondPtAngle = aStartDir->angle(aSecondPtDir);
+ double aPeriod = isReversed ? -2.0 * PI : 2.0 * PI;
+ if (isReversed == (aFirstPtAngle > 0.))
+ aFirstPtAngle += aPeriod;
+ if (isReversed == (aSecondPtAngle > 0.))
+ aSecondPtAngle += aPeriod;
+
+ if (fabs(aFirstPtAngle) > fabs(aSecondPtAngle)) {
+ AttributePoint2DPtr aTmpPoint = theFirstPointAttr;
+ theFirstPointAttr = theSecondPointAttr;
+ theSecondPointAttr = aTmpPoint;
+ }
+}
+
void SketchPlugin_ConstraintSplit::fillAttribute(const AttributePtr& theModifiedAttribute,
const AttributePtr& theSourceAttribute)
{
/// \param theEndPointAttr an end point of a segment
/// \param theFirstPointAttr a start point of a segment
/// \param theSecondPointAttr an end point of a segment
- void arrangePoints(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
- const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
- std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
- std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr);
+ void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
+ const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
+ std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
+ std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
+
+ /// Correct the first and the second point to provide condition that the first is closer to
+ /// the start point and the second point - to the last end of current segment. To rearrange
+ /// them if this condition is not satisfied.
+ /// \param theArc an arc to be split
+ /// \param theStartPointAttr a start point of a segment
+ /// \param theEndPointAttr an end point of a segment
+ /// \param theFirstPointAttr a start point of a segment
+ /// \param theSecondPointAttr an end point of a segment
+ void arrangePointsOnArc(const FeaturePtr& theArc,
+ const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
+ const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
+ std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
+ std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
/// Fill attribute by value of another attribute. It processes only Point 2D attributes.
/// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
SketchCircle_3_1 = Sketch_3.addCircle(50, 50, 50)
SketchPoint_3_1 = Sketch_3.addPoint(50, 0)
SketchPoint_3_2 = Sketch_3.addPoint(50, 100)
-SketchConstraintCoincidence_3_1 = Sketch_3.setCoincident(SketchPoint_3_1.coordinates(), SketchCircle_3_1.result()[0])
-SketchConstraintCoincidence_3_2 = Sketch_3.setCoincident(SketchPoint_3_2.coordinates(), SketchCircle_3_1.result()[0])
+SketchConstraintCoincidence_3_1 = Sketch_3.setCoincident(SketchPoint_3_1.coordinates(), SketchCircle_3_1.result()[1])
+SketchConstraintCoincidence_3_2 = Sketch_3.setCoincident(SketchPoint_3_2.coordinates(), SketchCircle_3_1.result()[1])
Sketch_3.addSplit(SketchCircle_3_1, SketchPoint_3_1.coordinates(), SketchPoint_3_2.coordinates())
model.do()
# Test split on arc with one point
Sketch_4 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-SketchArc_4_1 = Sketch_4.addArc(50, 50, 0, 50, 100, 50, True)
+SketchArc_4_1 = Sketch_4.addArc(50, 50, 50, 0, 0, 50, False)
Sketch_4.setFixed(SketchArc_4_1.startPoint())
Sketch_4.setFixed(SketchArc_4_1.endPoint())
Sketch_4.setRadius(SketchArc_4_1, 50)
SketchPoint_4_1 = Sketch_4.addPoint(50, 100)
-SketchConstraintCoincidence_4_1 = Sketch_4.setCoincident(SketchPoint_4_1.coordinates(), SketchArc_4_1.result()[0])
+SketchConstraintCoincidence_4_1 = Sketch_4.setCoincident(SketchPoint_4_1.coordinates(), SketchArc_4_1.result()[1])
Sketch_4.addSplit(SketchArc_4_1, SketchPoint_4_1.coordinates(), SketchArc_4_1.endPoint())
model.do()
# Test split on arc with two points
Sketch_5 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-SketchArc_5_1 = Sketch_5.addArc(50, 50, 0, 50, 100, 50, True)
+#SketchArc_5_1 = Sketch_5.addArc(50, 50, 6.69872981078, 75, 93.30127018922, 75, True)
+SketchArc_5_1 = Sketch_5.addArc(50, 50, 0, 50, 93.30127018922, 75, True)
Sketch_5.setFixed(SketchArc_5_1.startPoint())
Sketch_5.setFixed(SketchArc_5_1.endPoint())
Sketch_5.setRadius(SketchArc_5_1, 50)
-SketchPoint_5_1 = Sketch_5.addPoint(25, 93.301270189222)
-SketchPoint_5_2 = Sketch_5.addPoint(75, 93.301270189222)
-SketchConstraintCoincidence_5_1 = Sketch_5.setCoincident(SketchPoint_5_1.coordinates(), SketchArc_5_1.result()[0])
-SketchConstraintCoincidence_5_1 = Sketch_5.setCoincident(SketchPoint_5_2.coordinates(), SketchArc_5_1.result()[0])
-Sketch_5.addSplit(SketchArc_5_1, SketchPoint_5_1.coordinates(), SketchPoint_5_2.coordinates())
+SketchLine_5_1 = Sketch_5.addLine(25, 93.301270189222, 75, 93.301270189222)
+SketchConstraintCoincidence_5_1 = Sketch_5.setCoincident(SketchLine_5_1.startPoint(), SketchArc_5_1.result()[1])
+SketchConstraintCoincidence_5_2 = Sketch_5.setCoincident(SketchLine_5_1.endPoint(), SketchArc_5_1.result()[1])
+SketchConstraintHorizontal_5_1 = Sketch_5.setHorizontal(SketchLine_5_1.result()[0])
+SketchConstraintLength_5_1 = Sketch_5.setLength(SketchLine_5_1.result()[0], 50)
+Sketch_5.addSplit(SketchArc_5_1, SketchLine_5_1.startPoint(), SketchLine_5_1.endPoint())
model.do()
Sketch_5_feature = featureToCompositeFeature(Sketch_5.feature())
idList.append(Sketch_5_feature.subFeature(index).getKind())
assert(idList.count(SketchArcId) == 3)
-assert(idList.count(SketchPointId) == 2)
+assert(idList.count(SketchPointId) == 0)
assert(idList.count(SketchConstraintCoincidenceId) == 4)
assert(idList.count(SketchConstraintEqualId) == 2)
assert(idList.count(SketchConstraintTangentId) == 2)