1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_MarkerDriver.hxx>
25 #include <GEOMImpl_IMarker.hxx>
26 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
30 #include <GEOMUtils.hxx>
32 #include <BRepBuilderAPI_MakeFace.hxx>
33 #include <BRep_Tool.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Vertex.hxx>
42 #include <GC_MakePlane.hxx>
43 #include <Geom_Surface.hxx>
45 #include <Precision.hxx>
51 #include <Standard_ConstructionError.hxx>
53 //=======================================================================
56 //=======================================================================
57 const Standard_GUID& GEOMImpl_MarkerDriver::GetID()
59 static Standard_GUID aMarkerDriver("FF1BBB07-5D14-4df2-980B-3A668264EA16");
64 //=======================================================================
65 //function : GEOMImpl_MarkerDriver
67 //=======================================================================
68 GEOMImpl_MarkerDriver::GEOMImpl_MarkerDriver()
72 //=======================================================================
75 //=======================================================================
76 Standard_Integer GEOMImpl_MarkerDriver::Execute(TFunction_Logbook& log) const
78 if (Label().IsNull()) return 0;
79 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
81 GEOMImpl_IMarker aPI (aFunction);
82 Standard_Integer aType = aFunction->GetType();
86 if (aType == MARKER_CS) {
90 aPI.GetOrigin(OX, OY, OZ);
91 aPI.GetXDir(XDX, XDY, XDZ);
92 aPI.GetYDir(YDX, YDY, YDZ);
94 gp_Pnt aPO (OX, OY, OZ);
95 gp_Vec aVX (XDX, XDY, XDZ);
96 gp_Vec aVY (YDX, YDY, YDZ);
97 Standard_Real aTol = Precision::Confusion();
98 if (aVX.Magnitude() < aTol ||
99 aVY.Magnitude() < aTol ||
100 aVX.IsParallel(aVY, Precision::Angular())) {
101 Standard_ConstructionError::Raise("Degenerated or parallel directions given");
104 gp_Vec aN = aVX ^ aVY;
105 gp_Ax3 anA (aPO, aN, aVX);
108 double aTrimSize = 100.0;
109 aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
110 } else if (aType == MARKER_SHAPE) {
111 Handle(GEOM_Function) aRefShape = aPI.GetShape();
112 TopoDS_Shape aSh = aRefShape->GetValue();
113 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aSh);
116 double aTrimSize = 100.0;
117 aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
118 } else if (aType == MARKER_PNT2VEC) {
119 Handle(GEOM_Function) aRefOrigin = aPI.GetOrigin();
120 Handle(GEOM_Function) aRefXVec = aPI.GetXVec();
121 Handle(GEOM_Function) aRefYVec = aPI.GetYVec();
122 TopoDS_Shape aShapeOrigin = aRefOrigin->GetValue();
123 TopoDS_Shape aShapeXVec = aRefXVec->GetValue();
124 TopoDS_Shape aShapeYVec = aRefYVec->GetValue();
125 if (aShapeOrigin.ShapeType() != TopAbs_VERTEX || aShapeOrigin.IsNull()) return 0;
126 if (aShapeXVec.ShapeType() != TopAbs_EDGE || aShapeXVec.IsNull()) return 0;
127 if (aShapeYVec.ShapeType() != TopAbs_EDGE || aShapeYVec.IsNull()) return 0;
129 gp_Pnt aPO = BRep_Tool::Pnt( TopoDS::Vertex( aShapeOrigin ) );
131 gp_Pnt aPX1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeXVec ) ) );
132 gp_Pnt aPX2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeXVec ) ) );
133 gp_Vec aVX( aPX1, aPX2 );
135 gp_Pnt aPY1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeYVec ) ) );
136 gp_Pnt aPY2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeYVec ) ) );
137 gp_Vec aVY( aPY1, aPY2 );
139 if (aVX.Magnitude() < gp::Resolution() || aVY.Magnitude() < gp::Resolution())
140 Standard_ConstructionError::Raise
141 ("Local CS creation aborted: vector of zero length is given");
143 if ( aVX.IsParallel(aVY, Precision::Angular()))
144 Standard_ConstructionError::Raise("Parallel Vectors given");
146 gp_Vec aN = aVX ^ aVY;
147 gp_Ax3 anA (aPO, aN, aVX);
150 double aTrimSize = 100.0;
151 aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
155 if (aShape.IsNull()) return 0;
157 aFunction->SetValue(aShape);
159 log.SetTouched(Label());
165 //=======================================================================
166 //function : GEOMImpl_MarkerDriver_Type_
168 //=======================================================================
169 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MarkerDriver_Type_()
172 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
173 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
174 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
175 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
176 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
177 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
180 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
181 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MarkerDriver",
182 sizeof(GEOMImpl_MarkerDriver),
184 (Standard_Address)_Ancestors,
185 (Standard_Address)NULL);
190 //=======================================================================
191 //function : DownCast
193 //=======================================================================
194 const Handle(GEOMImpl_MarkerDriver) Handle(GEOMImpl_MarkerDriver)::DownCast
195 (const Handle(Standard_Transient)& AnObject)
197 Handle(GEOMImpl_MarkerDriver) _anOtherObject;
199 if (!AnObject.IsNull()) {
200 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MarkerDriver))) {
201 _anOtherObject = Handle(GEOMImpl_MarkerDriver)((Handle(GEOMImpl_MarkerDriver)&)AnObject);
205 return _anOtherObject ;