2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_LineDriver.hxx>
5 #include <GEOMImpl_ILine.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRep_Tool.hxx>
10 #include <BRepBuilderAPI_MakeEdge.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Shape.hxx>
17 #include <TopoDS_Vertex.hxx>
20 #include <Precision.hxx>
21 #include <Standard_ConstructionError.hxx>
22 #include <Standard_NullObject.hxx>
24 //=======================================================================
27 //=======================================================================
28 const Standard_GUID& GEOMImpl_LineDriver::GetID()
30 static Standard_GUID aLineDriver("FF1BBB06-5D14-4df2-980B-3A668264EA16");
35 //=======================================================================
36 //function : GEOMImpl_LineDriver
38 //=======================================================================
39 GEOMImpl_LineDriver::GEOMImpl_LineDriver()
43 //=======================================================================
46 //=======================================================================
47 Standard_Integer GEOMImpl_LineDriver::Execute(TFunction_Logbook& log) const
49 if (Label().IsNull()) return 0;
50 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
52 GEOMImpl_ILine aPI (aFunction);
53 Standard_Integer aType = aFunction->GetType();
57 if (aType == LINE_TWO_PNT) {
58 Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
59 Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
60 TopoDS_Shape aShape1 = aRefPnt1->GetValue();
61 TopoDS_Shape aShape2 = aRefPnt2->GetValue();
62 if (aShape1.ShapeType() != TopAbs_VERTEX ||
63 aShape2.ShapeType() != TopAbs_VERTEX) return 0;
64 if (aShape1.IsSame(aShape2)) {
65 Standard_ConstructionError::Raise("The end points must be different");
67 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
68 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
69 if (P1.Distance(P2) < Precision::Confusion()) {
70 Standard_ConstructionError::Raise("The end points are too close");
72 aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
74 } else if (aType == LINE_PNT_DIR) {
75 Handle(GEOM_Function) aRefPnt = aPI.GetPoint1();
76 Handle(GEOM_Function) aRefDir = aPI.GetPoint2();
77 TopoDS_Shape aShape1 = aRefPnt->GetValue();
78 TopoDS_Shape aShape2 = aRefDir->GetValue();
79 if (aShape1.ShapeType() != TopAbs_VERTEX ||
80 aShape2.ShapeType() != TopAbs_EDGE) return 0;
81 if (aShape1.IsSame(aShape2)) {
82 Standard_ConstructionError::Raise("The end points must be different");
84 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
86 TopoDS_Edge anE = TopoDS::Edge(aShape2);
88 TopExp::Vertices(anE, V1, V2, Standard_True);
89 if (V1.IsNull() || V2.IsNull()) {
90 Standard_NullObject::Raise("Line creation aborted: vector is not defined");
92 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
93 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
94 if (PV1.Distance(PV2) < Precision::Confusion()) {
95 Standard_ConstructionError::Raise("Vector with null magnitude");
98 gp_Pnt P2 (P1.XYZ() + PV2.XYZ() - PV1.XYZ());
99 aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
103 if (aShape.IsNull()) return 0;
104 aShape.Infinite(true);
106 aFunction->SetValue(aShape);
108 log.SetTouched(Label());
114 //=======================================================================
115 //function : GEOMImpl_LineDriver_Type_
117 //=======================================================================
118 Standard_EXPORT Handle_Standard_Type& GEOMImpl_LineDriver_Type_()
121 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
122 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
123 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
124 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
125 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
126 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
129 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
130 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_LineDriver",
131 sizeof(GEOMImpl_LineDriver),
133 (Standard_Address)_Ancestors,
134 (Standard_Address)NULL);
139 //=======================================================================
140 //function : DownCast
142 //=======================================================================
143 const Handle(GEOMImpl_LineDriver) Handle(GEOMImpl_LineDriver)::DownCast
144 (const Handle(Standard_Transient)& AnObject)
146 Handle(GEOMImpl_LineDriver) _anOtherObject;
148 if (!AnObject.IsNull()) {
149 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_LineDriver))) {
150 _anOtherObject = Handle(GEOMImpl_LineDriver)((Handle(GEOMImpl_LineDriver)&)AnObject);
154 return _anOtherObject ;