2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_PrismDriver.hxx>
5 #include <GEOMImpl_IPrism.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepPrimAPI_MakePrism.hxx>
10 #include <BRep_Tool.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Vertex.hxx>
18 #include <Precision.hxx>
20 #include <Standard_ConstructionError.hxx>
22 //=======================================================================
25 //=======================================================================
26 const Standard_GUID& GEOMImpl_PrismDriver::GetID()
28 static Standard_GUID aPrismDriver("FF1BBB17-5D14-4df2-980B-3A668264EA16");
33 //=======================================================================
34 //function : GEOMImpl_PrismDriver
36 //=======================================================================
37 GEOMImpl_PrismDriver::GEOMImpl_PrismDriver()
41 //=======================================================================
44 //=======================================================================
45 Standard_Integer GEOMImpl_PrismDriver::Execute(TFunction_Logbook& log) const
47 if (Label().IsNull()) return 0;
48 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
50 GEOMImpl_IPrism aCI (aFunction);
51 Standard_Integer aType = aFunction->GetType();
55 if (aType == PRISM_BASE_VEC_H) {
56 Handle(GEOM_Function) aRefBase = aCI.GetBase();
57 Handle(GEOM_Function) aRefVector = aCI.GetVector();
58 TopoDS_Shape aShapeBase = aRefBase->GetValue();
59 TopoDS_Shape aShapeVec = aRefVector->GetValue();
60 if (aShapeVec.ShapeType() == TopAbs_EDGE) {
61 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
63 TopExp::Vertices(anE, V1, V2, Standard_True);
64 if (!V1.IsNull() && !V2.IsNull()) {
65 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
66 if (Abs(aCI.GetH()) < Precision::Confusion()) {
67 Standard_ConstructionError::Raise("Absolute value of prism height is too small");
69 if (aV.Magnitude() > Precision::Confusion()) {
71 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV * aCI.GetH(), Standard_False).Shape();
75 } else if (aType == PRISM_BASE_TWO_PNT) {
76 Handle(GEOM_Function) aRefBase = aCI.GetBase();
77 Handle(GEOM_Function) aRefPnt1 = aCI.GetFirstPoint();
78 Handle(GEOM_Function) aRefPnt2 = aCI.GetLastPoint();
79 TopoDS_Shape aShapeBase = aRefBase->GetValue();
80 TopoDS_Shape aShapePnt1 = aRefPnt1->GetValue();
81 TopoDS_Shape aShapePnt2 = aRefPnt2->GetValue();
82 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
83 aShapePnt2.ShapeType() == TopAbs_VERTEX) {
84 TopoDS_Vertex V1 = TopoDS::Vertex(aShapePnt1);
85 TopoDS_Vertex V2 = TopoDS::Vertex(aShapePnt2);
86 if (!V1.IsNull() && !V2.IsNull()) {
87 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
88 if (aV.Magnitude() > gp::Resolution()) {
89 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
96 if (aShape.IsNull()) return 0;
98 aFunction->SetValue(aShape);
100 log.SetTouched(Label());
106 //=======================================================================
107 //function : GEOMImpl_PrismDriver_Type_
109 //=======================================================================
110 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PrismDriver_Type_()
113 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
114 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
115 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
116 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
117 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
118 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
121 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
122 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PrismDriver",
123 sizeof(GEOMImpl_PrismDriver),
125 (Standard_Address)_Ancestors,
126 (Standard_Address)NULL);
131 //=======================================================================
132 //function : DownCast
134 //=======================================================================
135 const Handle(GEOMImpl_PrismDriver) Handle(GEOMImpl_PrismDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
137 Handle(GEOMImpl_PrismDriver) _anOtherObject;
139 if (!AnObject.IsNull()) {
140 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PrismDriver))) {
141 _anOtherObject = Handle(GEOMImpl_PrismDriver)((Handle(GEOMImpl_PrismDriver)&)AnObject);
145 return _anOtherObject ;