static GeomShapePtr faceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theV1,
const std::shared_ptr<GeomAPI_Vertex> theV2,
const std::shared_ptr<GeomAPI_Vertex> theV3);
+static std::shared_ptr<GeomAPI_Face> makeRectangularFace(const std::shared_ptr<GeomAPI_Face> theFace,
+ const std::shared_ptr<GeomAPI_Pln> thePln);
//==================================================================================================
ConstructionPlugin_Plane::ConstructionPlugin_Plane()
data()->addAttribute(CREATION_METHOD_BY_OTHER_PLANE_OPTION(), ModelAPI_AttributeString::typeId());
data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
data()->addAttribute(DISTANCE(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(COINCIDENT_POINT(), ModelAPI_AttributeSelection::typeId());
}
//==================================================================================================
std::string aCreationMethodOption = string(CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
if(aCreationMethodOption == CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
aShape = createByDistanceFromOther();
+ } else if(aCreationMethodOption == CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
+ aShape = createByCoincidentPoint();
}
}
-
if(!aShape.get()) {
+ setError("Error: Could not create a plane.");
return;
}
+ removeResults(0);
ResultConstructionPtr aConstr = document()->createConstruction(data());
aConstr->setInfinite(true);
aConstr->setShape(aShape);
}
//==================================================================================================
-std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByDistanceFromOther()
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByDistanceFromOther()
{
AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::PLANE());
AttributeDoublePtr aDistAttr = data()->real(ConstructionPlugin_Plane::DISTANCE());
aOrig->translate(aDir, aDist);
std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(aOrig, aDir));
- // Create rectangular face close to the selected
- double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
- aFace->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
-
- // use all 8 points of the bounding box to find the 2D bounds
- bool isFirst = true;
- double aMinX2d, aMaxX2d, aMinY2d, aMaxY2d;
- for(int aXIsMin = 0; aXIsMin < 2; aXIsMin++) {
- for(int aYIsMin = 0; aYIsMin < 2; aYIsMin++) {
- for(int aZIsMin = 0; aZIsMin < 2; aZIsMin++) {
- std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(
- aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax));
- std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aPnt->to2D(aNewPln);
- if (isFirst || aPnt2d->x() < aMinX2d)
- aMinX2d = aPnt2d->x();
- if (isFirst || aPnt2d->y() < aMinY2d)
- aMinY2d = aPnt2d->y();
- if (isFirst || aPnt2d->x() > aMaxX2d)
- aMaxX2d = aPnt2d->x();
- if (isFirst || aPnt2d->y() > aMaxY2d)
- aMaxY2d = aPnt2d->y();
- if (isFirst)
- isFirst = !isFirst;
- }
- }
- }
- double aWgap = (aMaxX2d - aMinX2d) * 0.1;
- double aHgap = (aMaxY2d - aMinY2d) * 0.1;
- aPlane = GeomAlgoAPI_FaceBuilder::planarFace(aNewPln,
- aMinX2d - aWgap, aMinY2d - aHgap, aMaxX2d - aMinX2d + 2. * aWgap, aMaxY2d - aMinY2d + 2. * aHgap);
-
+ aPlane = makeRectangularFace(aFace, aNewPln);
}
return aPlane;
}
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByCoincidentPoint()
+{
+ // Get face.
+ AttributeSelectionPtr aFaceSelection = selection(PLANE());
+ GeomShapePtr aFaceShape = aFaceSelection->value();
+ if(!aFaceShape.get()) {
+ aFaceShape = aFaceSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aFaceShape));
+
+ // Get point.
+ AttributeSelectionPtr aPointSelection = selection(COINCIDENT_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> anOrig = aVertex->point();
+ std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
+ std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
+
+ std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(anOrig, aDir));
+
+ return makeRectangularFace(aFace, aNewPln);
+}
+
//==================================================================================================
GeomShapePtr faceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theV1,
const std::shared_ptr<GeomAPI_Vertex> theV2,
return aRes;
}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> makeRectangularFace(const std::shared_ptr<GeomAPI_Face> theFace,
+ const std::shared_ptr<GeomAPI_Pln> thePln)
+{
+ // Create rectangular face close to the selected
+ double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
+ theFace->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
+
+ // use all 8 points of the bounding box to find the 2D bounds
+ bool isFirst = true;
+ double aMinX2d, aMaxX2d, aMinY2d, aMaxY2d;
+ for(int aXIsMin = 0; aXIsMin < 2; aXIsMin++) {
+ for(int aYIsMin = 0; aYIsMin < 2; aYIsMin++) {
+ for(int aZIsMin = 0; aZIsMin < 2; aZIsMin++) {
+ std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(
+ aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax));
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aPnt->to2D(thePln);
+ if (isFirst || aPnt2d->x() < aMinX2d)
+ aMinX2d = aPnt2d->x();
+ if (isFirst || aPnt2d->y() < aMinY2d)
+ aMinY2d = aPnt2d->y();
+ if (isFirst || aPnt2d->x() > aMaxX2d)
+ aMaxX2d = aPnt2d->x();
+ if (isFirst || aPnt2d->y() > aMaxY2d)
+ aMaxY2d = aPnt2d->y();
+ if (isFirst)
+ isFirst = !isFirst;
+ }
+ }
+ }
+ double aWgap = (aMaxX2d - aMinX2d) * 0.1;
+ double aHgap = (aMaxY2d - aMinY2d) * 0.1;
+ std::shared_ptr<GeomAPI_Face> aResFace = GeomAlgoAPI_FaceBuilder::planarFace(thePln,
+ aMinX2d - aWgap, aMinY2d - aHgap, aMaxX2d - aMinX2d + 2. * aWgap, aMaxY2d - aMinY2d + 2. * aHgap);
+
+ return aResFace;
+}