+ GeomEdgePtr anEdge;
+ if (aLineShape->isEdge()) {
+ anEdge = aLineShape->edge();
+ }
+ else if (aLineShape->isCompound()) {
+ // create an edge which covers all edges from compounds (they are on the same line)
+ GeomPointPtr aFirst, aLast;
+ GeomXYZPtr aLineVec;
+ for(GeomAPI_ShapeIterator anIt(aLineShape); anIt.more(); anIt.next()) {
+ GeomEdgePtr aSub = anIt.current()->edge();
+ if (aSub.get() && aSub->isLine()) {
+ if (!aLineVec.get()) {
+ aFirst = aSub->firstPoint();
+ aLast = aSub->lastPoint();
+ } else { // set aFirst and aLast by extreme points
+ GeomXYZPtr aFirstVec = aSub->firstPoint()->xyz()->decreased(aFirst->xyz());
+ bool aSameDirection =
+ aSub->lastPoint()->xyz()->decreased(aSub->firstPoint()->xyz())->dot(aLineVec) > 0;
+ if (aLineVec->dot(aFirstVec) < -1.e-7) { // first point is changed
+ aFirst = aSameDirection ? aSub->firstPoint() : aSub->lastPoint();
+ } else { // last point is changed
+ aLast = aSameDirection ? aSub->lastPoint() : aSub->firstPoint();
+ }
+ }
+ aLineVec = aLast->xyz()->decreased(aFirst->xyz());
+ }
+ }
+ if (aLineVec.get())
+ anEdge = GeomAlgoAPI_EdgeBuilder::line(aFirst, aLast);
+ }
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+}
+
+void ConstructionPlugin_Axis::createAxisByPlaneAndPoint()
+{
+ // Get face.
+ AttributeSelectionPtr aFaceSelection = selection(PLANE());
+ GeomShapePtr aFaceShape = aFaceSelection->value();
+ if(!aFaceShape.get()) {
+ aFaceShape = aFaceSelection->context()->shape();
+ }
+ GeomFacePtr aFace;
+ if (aFaceShape->isFace()) {
+ aFace = aFaceShape->face();
+ }
+ else if (aFaceShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape);
+ aFace = anIt.current()->face();
+ }
+ if (!aFace)
+ return;
+ std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
+
+ // Get point.
+ AttributeSelectionPtr aPointSelection = selection(POINT());
+ GeomShapePtr aPointShape = aPointSelection->value();
+ if(!aPointShape.get()) {
+ aPointShape = aPointSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+
+ std::shared_ptr<GeomAPI_Pnt> aProjPnt = aPln->project(aPnt);
+
+ if(aProjPnt->isEqual(aPnt)) {
+ aPnt->translate(aPln->direction(), defaultAxisSize);
+ }
+
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aPnt, aProjPnt);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+}
+
+void ConstructionPlugin_Axis::createAxisByTwoPlanes()
+{
+ // Get face 1.
+ AttributeSelectionPtr aFaceSelection1 = selection(PLANE1());
+ GeomShapePtr aFaceShape1 = aFaceSelection1->value();
+ if(!aFaceShape1.get()) {
+ aFaceShape1 = aFaceSelection1->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace1;
+ if (aFaceShape1->isFace()) {
+ aFace1 = aFaceShape1->face();
+ }
+ else if (aFaceShape1->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape1);
+ aFace1 = anIt.current()->face();
+ }
+ if (!aFace1)
+ return;
+ std::shared_ptr<GeomAPI_Pln> aPln1 = aFace1->getPlane();
+
+ std::string useOffset1 = string(USE_OFFSET1())->value();
+ if(!useOffset1.empty()) {
+ double anOffset1 = real(OFFSET1())->value();
+ bool reverseOffset1 = boolean(REVERSE_OFFSET1())->value();
+ if(reverseOffset1) {
+ anOffset1 = -anOffset1;
+ }
+ aPln1->translate(aPln1->direction(), anOffset1);
+ }
+
+ // Get face 2.
+ AttributeSelectionPtr aFaceSelection2 = selection(PLANE2());
+ GeomShapePtr aFaceShape2 = aFaceSelection2->value();
+ if(!aFaceShape2.get()) {
+ aFaceShape2 = aFaceSelection2->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace2;
+ if (aFaceShape2->isFace()) {
+ aFace2 = aFaceShape2->face();
+ }
+ else if (aFaceShape2->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape2);
+ aFace2 = anIt.current()->face();
+ }
+ if (!aFace2)
+ return;
+ std::shared_ptr<GeomAPI_Pln> aPln2 = aFace2->getPlane();
+
+ std::string useOffset2 = string(USE_OFFSET2())->value();
+ if(!useOffset2.empty()) {
+ double anOffset2 = real(OFFSET2())->value();
+ bool reverseOffset2 = boolean(REVERSE_OFFSET2())->value();
+ if(reverseOffset2) {
+ anOffset2 = -anOffset2;
+ }
+ aPln2->translate(aPln2->direction(), anOffset2);
+ }
+
+ std::shared_ptr<GeomAPI_Lin> aLin = aPln1->intersect(aPln2);
+ std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLin->location();
+ std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLin->location();
+ aPnt2->translate(aLin->direction(), defaultAxisSize);
+
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aPnt1, aPnt2);