3 #include "GEOMImpl_VectorDriver.hxx"
4 #include "GEOMImpl_IVector.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRep_Tool.hxx>
9 #include <BRepBuilderAPI_MakeEdge.hxx>
13 #include <TopoDS_Shape.hxx>
14 #include <TopoDS_Vertex.hxx>
17 #include <Precision.hxx>
18 #include <TCollection_AsciiString.hxx>
19 #include <Standard_ConstructionError.hxx>
21 //=======================================================================
24 //=======================================================================
25 const Standard_GUID& GEOMImpl_VectorDriver::GetID()
27 static Standard_GUID aVectorDriver("FF1BBB04-5D14-4df2-980B-3A668264EA16");
32 //=======================================================================
33 //function : GEOMImpl_VectorDriver
35 //=======================================================================
36 GEOMImpl_VectorDriver::GEOMImpl_VectorDriver()
40 //=======================================================================
43 //=======================================================================
44 Standard_Integer GEOMImpl_VectorDriver::Execute(TFunction_Logbook& log) const
46 if (Label().IsNull()) return 0;
47 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
49 GEOMImpl_IVector aPI (aFunction);
50 Standard_Integer aType = aFunction->GetType();
51 if (aType != VECTOR_DX_DY_DZ && aType != VECTOR_TWO_PNT) return 0;
55 if (aType == VECTOR_DX_DY_DZ) {
56 gp_Pnt P1 = gp::Origin();
57 gp_Pnt P2 (aPI.GetDX(), aPI.GetDY(), aPI.GetDZ());
58 if (P1.Distance(P2) < Precision::Confusion()) {
59 TCollection_AsciiString aMsg ("Can not build vector with length, less than ");
60 aMsg += TCollection_AsciiString(Precision::Confusion());
61 Standard_ConstructionError::Raise(aMsg.ToCString());
63 aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
64 } else if (aType == VECTOR_TWO_PNT) {
65 Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
66 Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
67 TopoDS_Shape aShape1 = aRefPnt1->GetValue();
68 TopoDS_Shape aShape2 = aRefPnt2->GetValue();
69 if (aShape1.ShapeType() != TopAbs_VERTEX ||
70 aShape2.ShapeType() != TopAbs_VERTEX) return 0;
71 if (aShape1.IsSame(aShape2)) {
72 Standard_ConstructionError::Raise("The end points must be different");
74 TopoDS_Vertex V1 = TopoDS::Vertex(aShape1);
75 TopoDS_Vertex V2 = TopoDS::Vertex(aShape2);
76 gp_Pnt P1 = BRep_Tool::Pnt(V1);
77 gp_Pnt P2 = BRep_Tool::Pnt(V2);
78 if (P1.Distance(P2) < Precision::Confusion()) {
79 Standard_ConstructionError::Raise("The end points are too close");
81 aShape = BRepBuilderAPI_MakeEdge(V1, V2).Shape();
85 if (aShape.IsNull()) return 0;
87 aFunction->SetValue(aShape);
89 log.SetTouched(Label());
95 //=======================================================================
96 //function : GEOMImpl_VectorDriver_Type_
98 //=======================================================================
99 Standard_EXPORT Handle_Standard_Type& GEOMImpl_VectorDriver_Type_()
102 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
103 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
104 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
105 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
106 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
107 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
110 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
111 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_VectorDriver",
112 sizeof(GEOMImpl_VectorDriver),
114 (Standard_Address)_Ancestors,
115 (Standard_Address)NULL);
120 //=======================================================================
121 //function : DownCast
123 //=======================================================================
124 const Handle(GEOMImpl_VectorDriver) Handle(GEOMImpl_VectorDriver)::DownCast
125 (const Handle(Standard_Transient)& AnObject)
127 Handle(GEOMImpl_VectorDriver) _anOtherObject;
129 if (!AnObject.IsNull()) {
130 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_VectorDriver))) {
131 _anOtherObject = Handle(GEOMImpl_VectorDriver)((Handle(GEOMImpl_VectorDriver)&)AnObject);
135 return _anOtherObject ;