std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
- std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd, true);
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
aConstr->setShape(anEdge);
setResult(aConstr);
}
std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
aConstr->setShape(anEdge);
setResult(aConstr);
}
if (!aPlaneFace.get())
return;
ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
aConstr->setShape(aPlaneFace);
setResult(aConstr);
}
std::string kDefaultPlaneSize = "200";
double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize);
aSize *= 4.;
- aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize, true);
+ aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize);
}
return aPlaneFace;
}
#include <gp_Circ.hxx>
std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
- std::shared_ptr<GeomAPI_Pnt> theStart, std::shared_ptr<GeomAPI_Pnt> theEnd,
- const bool theInfinite)
+ std::shared_ptr<GeomAPI_Pnt> theStart, std::shared_ptr<GeomAPI_Pnt> theEnd)
{
const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
TopoDS_Edge anEdge = anEdgeBuilder.Edge();
- if (theInfinite)
- anEdge.Infinite(Standard_True);
aRes->setImpl(new TopoDS_Shape(anEdge));
return aRes;
}
/// Creates linear edge by two points.
/// \param theStart a first point of an edge
/// \param theEnd an end point of an edge
- /// \param theInfinite if true, the shape of the edge is infinite. It is used for axis edge.
static std::shared_ptr<GeomAPI_Edge> line(std::shared_ptr<GeomAPI_Pnt> theStart,
- std::shared_ptr<GeomAPI_Pnt> theEnd,
- const bool theInfinite = false);
+ std::shared_ptr<GeomAPI_Pnt> theEnd);
/// Creates edge - axis of the given cylindrical face. The result axis edge is infinite
static std::shared_ptr<GeomAPI_Edge> cylinderAxis(
std::shared_ptr<GeomAPI_Shape> theCylindricalFace);
std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
std::shared_ptr<GeomAPI_Pln> thePlane,
- const double theSize,
- const bool theInfinite)
+ const double theSize)
{
// half of the size in each direction from the center
BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl<gp_Pln>(),
-theSize / 2., theSize / 2.);
std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
TopoDS_Shape aFace = aFaceBuilder.Face();
- if (theInfinite)
- aFace.Infinite(Standard_True);
aRes->setImpl(new TopoDS_Shape(aFace/*aFaceBuilder.Face()*/));
return aRes;
}
/// Creates square planar face by given point of the center,
/// normal to the plane and size of square
static std::shared_ptr<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pln> thePlane,
- const double theSize,
- const bool theInfinite = false);
+ const double theSize);
/// Returns the plane of the planar face. If it is not planar, returns empty ptr.
static std::shared_ptr<GeomAPI_Pln> plane(std::shared_ptr<GeomAPI_Shape> theFace);
{
myIsDisabled = true; // by default it is not initialized and false to be after created
myIsInHistory = true;
+ myIsInfinite = false;
myFacesUpToDate = false;
setIsConcealed(false);
}
{
return myFaces[theIndex];
}
+
+bool Model_ResultConstruction::isInfinite()
+{
+ return myIsInfinite;
+}
+
+void Model_ResultConstruction::setInfinite(const bool theInfinite)
+{
+ myIsInfinite = theInfinite;
+}
bool myFacesUpToDate; ///< is true if faces in myuFaces are computed and up to date
std::vector<std::shared_ptr<GeomAPI_Face> > myFaces; ///< stores the up to date faces if they exist
bool myIsInHistory;
+ bool myIsInfinite;
public:
/// default color for a result construction
inline static const std::string& DEFAULT_COLOR()
/// if the construction result may be used as faces, this method returns face by zero based index
MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Face> face(const int theIndex);
+ /// By default object is not infinite.
+ MODEL_EXPORT virtual bool isInfinite();
+ /// Sets the flag that it is infinite
+ MODEL_EXPORT virtual void setInfinite(const bool theInfinite);
+
protected:
/// Makes a body on the given feature
Model_ResultConstruction();
virtual int facesNum() = 0;
/// if the construction result may be used as faces, this method returns face by zero based index
virtual std::shared_ptr<GeomAPI_Face> face(const int theIndex) = 0;
+
+ /// By default object is not infinite.
+ virtual bool isInfinite() = 0;
+ /// Sets the flag that it is infinite
+ virtual void setInfinite(const bool theInfinite) = 0;
};
//! Pointer on feature object
#include "PartSet_FilterInfinite.h"
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_ISelection.h>
+#include <ModelAPI_ResultConstruction.h>
+
#include <AIS_InteractiveObject.hxx>
#include <AIS_Shape.hxx>
#include <TopoDS_Shape.hxx>
IMPLEMENT_STANDARD_HANDLE(PartSet_FilterInfinite, SelectMgr_Filter);
IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
+PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop)
+: SelectMgr_Filter(), myWorkshop(theWorkshop)
+{
+}
+
Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
{
Standard_Boolean aValid = Standard_True;
- Handle(AIS_InteractiveObject) anAISObj =
- Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
- if (!anAISObj.IsNull()) {
- Handle(AIS_InteractiveObject) anObj =
- Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
- Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anObj);
- if (!aAISShape.IsNull()) {
- TopoDS_Shape anAISShape = aAISShape->Shape();
- if (!anAISShape.IsNull() && anAISShape.Infinite()) {
- aValid = Standard_False;
+
+ ModuleBase_ViewerPrs aPrs;
+ myWorkshop->selection()->fillPresentation(aPrs, theOwner);
+ ResultPtr aResult = myWorkshop->selection()->getResult(aPrs);
+ // to filter infinite construction results
+ if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) {
+ ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+ if (aConstruction.get() && aConstruction->isInfinite()) {
+ Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+ if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
+ const TopoDS_Shape& aShape = aBRepOwner->Shape();
+ TopAbs_ShapeEnum anOwnerShapeType = aShape.ShapeType();
+
+ TopAbs_ShapeEnum aResultShapeType = TopAbs_SHAPE;
+ GeomShapePtr aResultShape = aResult->shape();
+ if (aResultShape.get()) {
+ TopoDS_Shape aResultTopoShape = aResultShape->impl<TopoDS_Shape>();
+ aResultShapeType = aResultTopoShape.ShapeType();
+ }
// for infinite object, the selection is possible only for shapes of owners, which are coincide
// to the shape of corresponded AIS object. In other words, for axis, only edge can be selected
// (vertices are not selectable), for planes, only faces can be selected (not edges or vertices)
- TopoDS_Shape anOwnerShape;
- Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
- if( !aBRO.IsNull() ) {
- anOwnerShape = aBRO->Shape();
- if (!anOwnerShape.IsNull()) {
- aValid = anAISShape.ShapeType() == anOwnerShape.ShapeType();
- }
- }
+ aValid = anOwnerShapeType == aResultShapeType;
}
}
}
#include <SelectMgr_Filter.hxx>
+class ModuleBase_IWorkshop;
+
/**
* \class PartSet_FilterInfinite
* \ingroup Modules
public:
/// Constructor
/// \param theWorkshop a pointer to workshop
- PartSet_FilterInfinite()
- : SelectMgr_Filter() {}
+ PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop);
/// Returns True if selected presentation can be selected
/// \param theOwner an owner of the persentation
Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
DEFINE_STANDARD_RTTI(PartSet_FilterInfinite)
+
+protected:
+ /// Reference to workshop
+ ModuleBase_IWorkshop* myWorkshop;
};
#endif
\ No newline at end of file
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
- mySelectionFilters.Append(new PartSet_FilterInfinite());
+ mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
}
PartSet_Module::~PartSet_Module()