Back to index

salome-geom  6.5.0
GEOMImpl_FaceDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include <Standard_Stream.hxx>
00021 
00022 #include <GEOMImpl_FaceDriver.hxx>
00023 #include <GEOMImpl_IFace.hxx>
00024 #include <GEOMImpl_Types.hxx>
00025 #include <GEOM_Function.hxx>
00026 
00027 #include <GEOMImpl_IMeasureOperations.hxx>
00028 
00029 #include <BRepBuilderAPI_MakeFace.hxx>
00030 #include <BRep_Tool.hxx>
00031 #include <gp_Pnt.hxx>
00032 #include <gp_Pln.hxx>
00033 #include <TopoDS.hxx>
00034 #include <TopoDS_Shape.hxx>
00035 #include <TopoDS_Edge.hxx>
00036 #include <TopoDS_Face.hxx>
00037 #include <TopoDS_Vertex.hxx>
00038 #include <TopAbs.hxx>
00039 #include <TopExp.hxx>
00040 
00041 #include <StdFail_NotDone.hxx>
00042 
00043 //=======================================================================
00044 //function : GetID
00045 //purpose  :
00046 //=======================================================================
00047 const Standard_GUID& GEOMImpl_FaceDriver::GetID()
00048 {
00049   static Standard_GUID aFaceDriver("F7953CC1-FF8B-4628-BF5E-9D3510DE4629");
00050   return aFaceDriver;
00051 }
00052 
00053 
00054 //=======================================================================
00055 //function : GEOMImpl_FaceDriver
00056 //purpose  :
00057 //=======================================================================
00058 GEOMImpl_FaceDriver::GEOMImpl_FaceDriver()
00059 {
00060 }
00061 
00062 //=======================================================================
00063 //function : Execute
00064 //purpose  :
00065 //=======================================================================
00066 Standard_Integer GEOMImpl_FaceDriver::Execute(TFunction_Logbook& log) const
00067 {
00068   if (Label().IsNull()) return 0;
00069   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00070 
00071   GEOMImpl_IFace aFI (aFunction);
00072   Standard_Integer aType = aFunction->GetType();
00073 
00074   TopoDS_Shape aShape;
00075 
00076   if (aType == FACE_OBJ_H_W) {
00077     Handle(GEOM_Function) aRefFunct = aFI.GetRef1();
00078     TopoDS_Shape aRefShape = aRefFunct->GetValue();
00079     if (aRefShape.ShapeType() == TopAbs_EDGE) {
00080       TopoDS_Edge anEdge = TopoDS::Edge(aRefShape);
00081       double aH = aFI.GetH() / 2.0;
00082       double aW = aFI.GetW() / 2.0;
00083       TopoDS_Vertex V1, V2;
00084       TopExp::Vertices(anEdge, V1, V2, Standard_True);
00085       gp_Pnt aP (BRep_Tool::Pnt(V1));
00086       gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
00087       gp_Pln aPlane (aP, aV);
00088       aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
00089     } else if (aRefShape.ShapeType() == TopAbs_FACE) {
00090       double aH = aFI.GetH() / 2.0;
00091       double aW = aFI.GetW() / 2.0;
00092       gp_Ax3 anAx = GEOMImpl_IMeasureOperations::GetPosition(aRefShape);
00093       gp_Pln aPln (anAx);
00094       aShape = BRepBuilderAPI_MakeFace(aPln, -aH, +aH, -aW, +aW).Shape();
00095     }
00096   }
00097   else if (aType == FACE_H_W) {
00098     double aH = aFI.GetH() / 2.0;
00099     double aW = aFI.GetW() / 2.0;
00100     TopoDS_Vertex V1, V2;
00101     int anOrient = aFI.GetOrientation();
00102     gp_Pnt aP = gp::Origin();
00103     gp_Vec aV;
00104     if (anOrient == 1)
00105       aV = gp::DZ();
00106     else if (anOrient == 2)
00107       aV = gp::DX();
00108     else if (anOrient == 3)
00109       aV = gp::DY();
00110 
00111     gp_Pln aPlane (aP, aV);
00112     aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
00113   }
00114   else {
00115   }
00116 
00117   if (aShape.IsNull()) return 0;
00118 
00119   aFunction->SetValue(aShape);
00120 
00121   log.SetTouched(Label());
00122 
00123   return 1;
00124 }
00125 
00126 
00127 //=======================================================================
00128 //function :  GEOMImpl_FaceDriver_Type_
00129 //purpose  :
00130 //=======================================================================
00131 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FaceDriver_Type_()
00132 {
00133 
00134   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00135   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00136   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00137   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00138   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00139   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00140 
00141 
00142   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00143   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FaceDriver",
00144                                                          sizeof(GEOMImpl_FaceDriver),
00145                                                          1,
00146                                                          (Standard_Address)_Ancestors,
00147                                                          (Standard_Address)NULL);
00148 
00149   return _aType;
00150 }
00151 
00152 //=======================================================================
00153 //function : DownCast
00154 //purpose  :
00155 //=======================================================================
00156 const Handle(GEOMImpl_FaceDriver) Handle(GEOMImpl_FaceDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00157 {
00158   Handle(GEOMImpl_FaceDriver) _anOtherObject;
00159 
00160   if (!AnObject.IsNull()) {
00161      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FaceDriver))) {
00162        _anOtherObject = Handle(GEOMImpl_FaceDriver)((Handle(GEOMImpl_FaceDriver)&)AnObject);
00163      }
00164   }
00165 
00166   return _anOtherObject ;
00167 }