3 #include "GEOMImpl_PrismDriver.hxx"
4 #include "GEOMImpl_IPrism.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepPrimAPI_MakePrism.hxx>
9 #include <BRep_Tool.hxx>
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Edge.hxx>
13 #include <TopoDS_Vertex.hxx>
17 #include <Precision.hxx>
19 #include <Standard_ConstructionError.hxx>
21 //=======================================================================
24 //=======================================================================
25 const Standard_GUID& GEOMImpl_PrismDriver::GetID()
27 static Standard_GUID aPrismDriver("FF1BBB17-5D14-4df2-980B-3A668264EA16");
32 //=======================================================================
33 //function : GEOMImpl_PrismDriver
35 //=======================================================================
36 GEOMImpl_PrismDriver::GEOMImpl_PrismDriver()
40 //=======================================================================
43 //=======================================================================
44 Standard_Integer GEOMImpl_PrismDriver::Execute(TFunction_Logbook& log) const
46 if (Label().IsNull()) return 0;
47 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
49 GEOMImpl_IPrism aCI (aFunction);
50 Standard_Integer aType = aFunction->GetType();
54 if (aType == PRISM_BASE_VEC_H) {
55 Handle(GEOM_Function) aRefBase = aCI.GetBase();
56 Handle(GEOM_Function) aRefVector = aCI.GetVector();
57 TopoDS_Shape aShapeBase = aRefBase->GetValue();
58 TopoDS_Shape aShapeVec = aRefVector->GetValue();
59 if (aShapeVec.ShapeType() == TopAbs_EDGE) {
60 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
62 TopExp::Vertices(anE, V1, V2, Standard_True);
63 if (!V1.IsNull() && !V2.IsNull()) {
64 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
65 if (Abs(aCI.GetH()) < Precision::Confusion()) {
66 Standard_ConstructionError::Raise("Absolute value of prism height is too small");
68 if (aV.Magnitude() > Precision::Confusion()) {
70 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV * aCI.GetH(), Standard_False).Shape();
74 } else if (aType == PRISM_BASE_TWO_PNT) {
75 Handle(GEOM_Function) aRefBase = aCI.GetBase();
76 Handle(GEOM_Function) aRefPnt1 = aCI.GetFirstPoint();
77 Handle(GEOM_Function) aRefPnt2 = aCI.GetLastPoint();
78 TopoDS_Shape aShapeBase = aRefBase->GetValue();
79 TopoDS_Shape aShapePnt1 = aRefPnt1->GetValue();
80 TopoDS_Shape aShapePnt2 = aRefPnt2->GetValue();
81 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
82 aShapePnt2.ShapeType() == TopAbs_VERTEX) {
83 TopoDS_Vertex V1 = TopoDS::Vertex(aShapePnt1);
84 TopoDS_Vertex V2 = TopoDS::Vertex(aShapePnt2);
85 if (!V1.IsNull() && !V2.IsNull()) {
86 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
87 if (aV.Magnitude() > gp::Resolution()) {
88 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
95 if (aShape.IsNull()) return 0;
97 aFunction->SetValue(aShape);
99 log.SetTouched(Label());
105 //=======================================================================
106 //function : GEOMImpl_PrismDriver_Type_
108 //=======================================================================
109 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PrismDriver_Type_()
112 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
113 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
114 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
115 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
116 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
117 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
120 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
121 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PrismDriver",
122 sizeof(GEOMImpl_PrismDriver),
124 (Standard_Address)_Ancestors,
125 (Standard_Address)NULL);
130 //=======================================================================
131 //function : DownCast
133 //=======================================================================
134 const Handle(GEOMImpl_PrismDriver) Handle(GEOMImpl_PrismDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
136 Handle(GEOMImpl_PrismDriver) _anOtherObject;
138 if (!AnObject.IsNull()) {
139 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PrismDriver))) {
140 _anOtherObject = Handle(GEOMImpl_PrismDriver)((Handle(GEOMImpl_PrismDriver)&)AnObject);
144 return _anOtherObject ;