Back to index

salome-geom  6.5.0
GEOMImpl_MarkerDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOMImpl_MarkerDriver.hxx>
00026 #include <GEOMImpl_IMarker.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 #include <GEOMImpl_IMeasureOperations.hxx>
00030 
00031 #include <BRepBuilderAPI_MakeFace.hxx>
00032 #include <BRep_Tool.hxx>
00033 
00034 #include <TopAbs.hxx>
00035 #include <TopoDS.hxx>
00036 #include <TopoDS_Shape.hxx>
00037 #include <TopoDS_Edge.hxx>
00038 #include <TopoDS_Vertex.hxx>
00039 #include <TopExp.hxx>
00040 
00041 #include <GC_MakePlane.hxx>
00042 #include <Geom_Surface.hxx>
00043 
00044 #include <Precision.hxx>
00045 #include <gp_Ax3.hxx>
00046 #include <gp_Pnt.hxx>
00047 #include <gp_Pln.hxx>
00048 #include <gp_Vec.hxx>
00049 
00050 #include <Standard_ConstructionError.hxx>
00051 
00052 //=======================================================================
00053 //function : GetID
00054 //purpose  :
00055 //=======================================================================
00056 const Standard_GUID& GEOMImpl_MarkerDriver::GetID()
00057 {
00058   static Standard_GUID aMarkerDriver("FF1BBB07-5D14-4df2-980B-3A668264EA16");
00059   return aMarkerDriver;
00060 }
00061 
00062 
00063 //=======================================================================
00064 //function : GEOMImpl_MarkerDriver
00065 //purpose  :
00066 //=======================================================================
00067 GEOMImpl_MarkerDriver::GEOMImpl_MarkerDriver()
00068 {
00069 }
00070 
00071 //=======================================================================
00072 //function : Execute
00073 //purpose  :
00074 //=======================================================================
00075 Standard_Integer GEOMImpl_MarkerDriver::Execute(TFunction_Logbook& log) const
00076 {
00077   if (Label().IsNull())  return 0;
00078   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00079 
00080   GEOMImpl_IMarker aPI (aFunction);
00081   Standard_Integer aType = aFunction->GetType();
00082 
00083   TopoDS_Shape aShape;
00084 
00085   if (aType == MARKER_CS) {
00086     double OX, OY, OZ;
00087     double XDX, XDY, XDZ;
00088     double YDX, YDY, YDZ;
00089     aPI.GetOrigin(OX, OY, OZ);
00090     aPI.GetXDir(XDX, XDY, XDZ);
00091     aPI.GetYDir(YDX, YDY, YDZ);
00092 
00093     gp_Pnt aPO (OX, OY, OZ);
00094     gp_Vec aVX (XDX, XDY, XDZ);
00095     gp_Vec aVY (YDX, YDY, YDZ);
00096     Standard_Real aTol = Precision::Confusion();
00097     if (aVX.Magnitude() < aTol ||
00098         aVY.Magnitude() < aTol ||
00099         aVX.IsParallel(aVY, Precision::Angular())) {
00100       Standard_ConstructionError::Raise("Degenerated or parallel directions given");
00101     }
00102 
00103     gp_Vec aN = aVX ^ aVY;
00104     gp_Ax3 anA (aPO, aN, aVX);
00105     gp_Pln aPln (anA);
00106 
00107     double aTrimSize = 100.0;
00108     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
00109   } else if (aType == MARKER_SHAPE) {
00110     Handle(GEOM_Function) aRefShape = aPI.GetShape();
00111     TopoDS_Shape aSh = aRefShape->GetValue();
00112     gp_Ax3 anAx3 = GEOMImpl_IMeasureOperations::GetPosition(aSh);
00113     gp_Pln aPln (anAx3);
00114 
00115     double aTrimSize = 100.0;
00116     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
00117   } else if (aType == MARKER_PNT2VEC) {
00118     Handle(GEOM_Function) aRefOrigin  = aPI.GetOrigin();
00119     Handle(GEOM_Function) aRefXVec = aPI.GetXVec();
00120     Handle(GEOM_Function) aRefYVec = aPI.GetYVec();
00121     TopoDS_Shape aShapeOrigin = aRefOrigin->GetValue();
00122     TopoDS_Shape aShapeXVec = aRefXVec->GetValue();
00123     TopoDS_Shape aShapeYVec = aRefYVec->GetValue();
00124     if (aShapeOrigin.ShapeType() != TopAbs_VERTEX || aShapeOrigin.IsNull()) return 0;
00125     if (aShapeXVec.ShapeType() != TopAbs_EDGE || aShapeXVec.IsNull()) return 0;
00126     if (aShapeYVec.ShapeType() != TopAbs_EDGE || aShapeYVec.IsNull()) return 0;
00127 
00128     gp_Pnt aPO = BRep_Tool::Pnt( TopoDS::Vertex( aShapeOrigin ) );
00129 
00130     gp_Pnt aPX1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeXVec ) ) );
00131     gp_Pnt aPX2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeXVec ) ) );
00132     gp_Vec aVX( aPX1, aPX2 );
00133 
00134     gp_Pnt aPY1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeYVec ) ) );
00135     gp_Pnt aPY2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeYVec ) ) );
00136     gp_Vec aVY( aPY1, aPY2 );
00137 
00138     if (aVX.Magnitude() < gp::Resolution() || aVY.Magnitude() < gp::Resolution())
00139         Standard_ConstructionError::Raise
00140           ("Local CS creation aborted: vector of zero length is given");
00141 
00142     if ( aVX.IsParallel(aVY, Precision::Angular()))
00143       Standard_ConstructionError::Raise("Parallel Vectors given");
00144     
00145     gp_Vec aN = aVX ^ aVY;
00146     gp_Ax3 anA (aPO, aN, aVX);
00147     gp_Pln aPln (anA);
00148     
00149     double aTrimSize = 100.0;
00150     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
00151   } else {
00152   }
00153 
00154   if (aShape.IsNull()) return 0;
00155 
00156   aFunction->SetValue(aShape);
00157 
00158   log.SetTouched(Label());
00159 
00160   return 1;
00161 }
00162 
00163 
00164 //=======================================================================
00165 //function :  GEOMImpl_MarkerDriver_Type_
00166 //purpose  :
00167 //=======================================================================
00168 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MarkerDriver_Type_()
00169 {
00170 
00171   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00172   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00173   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00174   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00175   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00176   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00177 
00178 
00179   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00180   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MarkerDriver",
00181                                                          sizeof(GEOMImpl_MarkerDriver),
00182                                                          1,
00183                                                          (Standard_Address)_Ancestors,
00184                                                          (Standard_Address)NULL);
00185 
00186   return _aType;
00187 }
00188 
00189 //=======================================================================
00190 //function : DownCast
00191 //purpose  :
00192 //=======================================================================
00193 const Handle(GEOMImpl_MarkerDriver) Handle(GEOMImpl_MarkerDriver)::DownCast
00194        (const Handle(Standard_Transient)& AnObject)
00195 {
00196   Handle(GEOMImpl_MarkerDriver) _anOtherObject;
00197 
00198   if (!AnObject.IsNull()) {
00199      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MarkerDriver))) {
00200        _anOtherObject = Handle(GEOMImpl_MarkerDriver)((Handle(GEOMImpl_MarkerDriver)&)AnObject);
00201      }
00202   }
00203 
00204   return _anOtherObject ;
00205 }