3 #include "GEOMImpl_LineDriver.hxx"
4 #include "GEOMImpl_ILine.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRep_Tool.hxx>
9 #include <BRepBuilderAPI_MakeEdge.hxx>
14 #include <TopoDS_Edge.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopoDS_Vertex.hxx>
19 #include <Precision.hxx>
20 #include <Standard_ConstructionError.hxx>
21 #include <Standard_NullObject.hxx>
23 //=======================================================================
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_LineDriver::GetID()
29 static Standard_GUID aLineDriver("FF1BBB06-5D14-4df2-980B-3A668264EA16");
34 //=======================================================================
35 //function : GEOMImpl_LineDriver
37 //=======================================================================
38 GEOMImpl_LineDriver::GEOMImpl_LineDriver()
42 //=======================================================================
45 //=======================================================================
46 Standard_Integer GEOMImpl_LineDriver::Execute(TFunction_Logbook& log) const
48 if (Label().IsNull()) return 0;
49 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51 GEOMImpl_ILine aPI (aFunction);
52 Standard_Integer aType = aFunction->GetType();
56 if (aType == LINE_TWO_PNT) {
57 Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
58 Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
59 TopoDS_Shape aShape1 = aRefPnt1->GetValue();
60 TopoDS_Shape aShape2 = aRefPnt2->GetValue();
61 if (aShape1.ShapeType() != TopAbs_VERTEX ||
62 aShape2.ShapeType() != TopAbs_VERTEX) return 0;
63 if (aShape1.IsSame(aShape2)) {
64 Standard_ConstructionError::Raise("The end points must be different");
66 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
67 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
68 if (P1.Distance(P2) < Precision::Confusion()) {
69 Standard_ConstructionError::Raise("The end points are too close");
71 aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
73 } else if (aType == LINE_PNT_DIR) {
74 Handle(GEOM_Function) aRefPnt = aPI.GetPoint1();
75 Handle(GEOM_Function) aRefDir = aPI.GetPoint2();
76 TopoDS_Shape aShape1 = aRefPnt->GetValue();
77 TopoDS_Shape aShape2 = aRefDir->GetValue();
78 if (aShape1.ShapeType() != TopAbs_VERTEX ||
79 aShape2.ShapeType() != TopAbs_EDGE) return 0;
80 if (aShape1.IsSame(aShape2)) {
81 Standard_ConstructionError::Raise("The end points must be different");
83 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
85 TopoDS_Edge anE = TopoDS::Edge(aShape2);
87 TopExp::Vertices(anE, V1, V2, Standard_True);
88 if (V1.IsNull() || V2.IsNull()) {
89 Standard_NullObject::Raise("Line creation aborted: vector is not defined");
91 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
92 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
93 if (PV1.Distance(PV2) < Precision::Confusion()) {
94 Standard_ConstructionError::Raise("Vector with null magnitude");
97 gp_Pnt P2 (P1.XYZ() + PV2.XYZ() - PV1.XYZ());
98 aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
102 if (aShape.IsNull()) return 0;
103 aShape.Infinite(true);
105 aFunction->SetValue(aShape);
107 log.SetTouched(Label());
113 //=======================================================================
114 //function : GEOMImpl_LineDriver_Type_
116 //=======================================================================
117 Standard_EXPORT Handle_Standard_Type& GEOMImpl_LineDriver_Type_()
120 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
121 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
122 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
123 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
124 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
125 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
128 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
129 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_LineDriver",
130 sizeof(GEOMImpl_LineDriver),
132 (Standard_Address)_Ancestors,
133 (Standard_Address)NULL);
138 //=======================================================================
139 //function : DownCast
141 //=======================================================================
142 const Handle(GEOMImpl_LineDriver) Handle(GEOMImpl_LineDriver)::DownCast
143 (const Handle(Standard_Transient)& AnObject)
145 Handle(GEOMImpl_LineDriver) _anOtherObject;
147 if (!AnObject.IsNull()) {
148 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_LineDriver))) {
149 _anOtherObject = Handle(GEOMImpl_LineDriver)((Handle(GEOMImpl_LineDriver)&)AnObject);
153 return _anOtherObject ;