+ if(!aBaseLoc.get()) {
+ gp_Pnt aLoc;
+ gp_XYZ aDirXYZ = aBaseVec.XYZ();
+ Standard_Real aMinParam = Precision::Infinite();
+ for(TopExp_Explorer anExp(aBaseShape, TopAbs_VERTEX); anExp.More(); anExp.Next()) {
+ const TopoDS_Shape& aVertex = anExp.Current();
+ gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVertex));
+ double aParam = aDirXYZ.Dot(aPnt.XYZ());
+ if(aParam < aMinParam) {
+ aMinParam = aParam;
+ aLoc = aPnt;
+ }
+ }
+ aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
+ }
+
+ GeomShapePtr aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir);
+
+ gp_Vec anExtVec;
+ std::shared_ptr<GeomAPI_Dir> anExtDir;
+ if (theDirection.get())
+ {
+ anExtDir = theDirection;
+ anExtVec = theDirection->impl<gp_Dir>();
+ }
+ else
+ {
+ anExtDir = aBaseDir;
+ anExtVec = aBaseDir->impl<gp_Dir>();
+ }
+
+
+ TopoDS_Shape aResult;
+ const bool isBoundingShapesSet = theFromShape.get() || theToShape.get();
+ if(!isBoundingShapesSet) {
+ // Moving base shape.
+ gp_Trsf aTrsf;
+ aTrsf.SetTranslation(anExtVec * -theFromSize);
+ BRepBuilderAPI_Transform* aTransformBuilder =
+ new BRepBuilderAPI_Transform(aBaseShape, aTrsf);
+ if(!aTransformBuilder || !aTransformBuilder->IsDone()) {
+ return;
+ }
+ this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(
+ new GeomAlgoAPI_MakeShape(aTransformBuilder)));
+ TopoDS_Shape aMovedBase = aTransformBuilder->Shape();
+
+ // Making prism.
+ BRepPrimAPI_MakePrism* aPrismBuilder =
+ new BRepPrimAPI_MakePrism(aMovedBase, anExtVec * (theFromSize + theToSize));
+ if(!aPrismBuilder || !aPrismBuilder->IsDone()) {
+ return;
+ }
+ this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(
+ new GeomAlgoAPI_MakeShape(aPrismBuilder)));
+ aResult = aPrismBuilder->Shape();
+
+ // Setting naming.
+ if(aShapeTypeToExp == TopAbs_COMPOUND) {
+ storeGenerationHistory(this, aMovedBase, TopAbs_EDGE, aPrismBuilder);
+ storeGenerationHistory(this, aMovedBase, TopAbs_FACE, aPrismBuilder);
+ } else {
+ storeGenerationHistory(this, aMovedBase, aShapeTypeToExp, aPrismBuilder);
+ }
+ } else {
+ GeomShapePtr aBoundingFromShape = theFromShape ? theFromShape : aBasePlane;
+ GeomShapePtr aBoundingToShape = theToShape ? theToShape : aBasePlane;
+
+ // Moving prism bounding faces according to "from" and "to" sizes.
+ std::shared_ptr<GeomAPI_Pln> aFromPln = GeomAPI_Face(aBoundingFromShape).getPlane();
+ std::shared_ptr<GeomAPI_Pnt> aFromLoc = aFromPln->location();
+ std::shared_ptr<GeomAPI_Dir> aFromDir = aFromPln->direction();
+
+ std::shared_ptr<GeomAPI_Pln> aToPln = GeomAPI_Face(aBoundingToShape).getPlane();
+ std::shared_ptr<GeomAPI_Pnt> aToLoc = aToPln->location();
+ std::shared_ptr<GeomAPI_Dir> aToDir = aToPln->direction();
+
+ bool aSign = aFromLoc->xyz()->dot(anExtDir->xyz()) > aToLoc->xyz()->dot(anExtDir->xyz());
+
+ std::shared_ptr<GeomAPI_Pnt> aFromPnt(
+ new GeomAPI_Pnt(aFromLoc->xyz()->added(anExtDir->xyz()->multiplied(
+ aSign ? theFromSize : -theFromSize))));
+ aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
+
+ std::shared_ptr<GeomAPI_Pnt> aToPnt(
+ new GeomAPI_Pnt(aToLoc->xyz()->added(anExtDir->xyz()->multiplied(
+ aSign ? -theToSize : theToSize))));
+ aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
+
+ // Getting bounding box for base shape.
+ Bnd_Box aBndBox;
+ BRepBndLib::Add(aBaseShape, aBndBox);
+ Standard_Real aXArr[2] = {aBndBox.CornerMin().X(), aBndBox.CornerMax().X()};
+ Standard_Real aYArr[2] = {aBndBox.CornerMin().Y(), aBndBox.CornerMax().Y()};
+ Standard_Real aZArr[2] = {aBndBox.CornerMin().Z(), aBndBox.CornerMax().Z()};
+ gp_Pnt aPoints[8];
+ int aNum = 0;
+ for(int i = 0; i < 2; i++) {
+ for(int j = 0; j < 2; j++) {
+ for(int k = 0; k < 2; k++) {
+ aPoints[aNum] = gp_Pnt(aXArr[i], aYArr[j], aZArr[k]);
+ aNum++;
+ }
+ }
+ }
+
+ // Project points to bounding planes. Search max distance to them.
+ IntAna_Quadric aBndToQuadric(gp_Pln(aToPnt->impl<gp_Pnt>(), aToDir->impl<gp_Dir>()));
+ IntAna_Quadric aBndFromQuadric(gp_Pln(aFromPnt->impl<gp_Pnt>(), aFromDir->impl<gp_Dir>()));
+ Standard_Real aMaxToDist = 0, aMaxFromDist = 0;
+ for(int i = 0; i < 8; i++) {
+ gp_Lin aLine(aPoints[i], anExtVec);
+ IntAna_IntConicQuad aToIntAna(aLine, aBndToQuadric);
+ IntAna_IntConicQuad aFromIntAna(aLine, aBndFromQuadric);
+ if(aToIntAna.NbPoints() == 0 || aFromIntAna.NbPoints() == 0) {