Back to index

salome-geom  6.5.0
GEOMImpl_SketcherDriver.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_SketcherDriver.hxx>
00026 #include <GEOMImpl_ISketcher.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <GEOMImpl_IMeasureOperations.hxx>
00031 
00032 #include <Basics_Utils.hxx>
00033 
00034 // OCCT Includes
00035 #include <BRepBuilderAPI_Transform.hxx>
00036 #include <BRep_Tool.hxx>
00037 #include <Geom_Plane.hxx>
00038 #include <TopoDS.hxx>
00039 #include <TopoDS_Shape.hxx>
00040 #include <gp_Pln.hxx>
00041 
00042 #include <Sketcher_Profile.hxx>
00043 
00044 #include <Standard_ConstructionError.hxx>
00045 
00046 //=======================================================================
00047 //function : GetID
00048 //purpose  :
00049 //=======================================================================
00050 const Standard_GUID& GEOMImpl_SketcherDriver::GetID()
00051 {
00052   static Standard_GUID aSketcherDriver("FF1BBB64-5D14-4df2-980B-3A668264EA16");
00053   return aSketcherDriver;
00054 }
00055 
00056 
00057 //=======================================================================
00058 //function : GEOMImpl_SketcherDriver
00059 //purpose  :
00060 //=======================================================================
00061 GEOMImpl_SketcherDriver::GEOMImpl_SketcherDriver()
00062 {
00063 }
00064 
00065 //=======================================================================
00066 //function : Execute
00067 //purpose  :
00068 //=======================================================================
00069 Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const
00070 {
00071   if (Label().IsNull()) return 0;
00072   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00073 
00074   GEOMImpl_ISketcher aCI (aFunction);
00075   //Standard_Integer aType = aFunction->GetType();
00076 
00077   // retrieve the command
00078   TCollection_AsciiString aCommand = aCI.GetCommand();
00079   if (aCommand.IsEmpty())
00080     return 0;
00081 
00082   TopoDS_Shape aShape;
00083 
00084   // Set "C" numeric locale to save numbers correctly
00085   Kernel_Utils::Localizer loc;
00086 
00087   // create sketcher
00088   Sketcher_Profile aProfile (aCommand.ToCString());
00089 
00090   if (!aProfile.IsDone()) {
00091     Standard_ConstructionError::Raise("Sketcher creation failed");
00092   }
00093 
00094   aShape = aProfile.GetShape();
00095   if (aShape.IsNull())
00096     return 0;
00097 
00098   gp_Ax3 aWPlane;
00099   if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS )
00100   {
00101     gp_Pnt aOrigin =
00102       gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
00103     gp_Dir aDirZ =
00104       gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
00105     gp_Dir aDirX =
00106       gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
00107     aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
00108   }
00109   else
00110   {
00111     Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane();
00112     TopoDS_Shape aShape = aRefFace->GetValue();
00113     //if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE )
00114     //  return 0;
00115     //Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ));
00116     //if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane )))
00117     //  return 0;
00118     //Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
00119     //aWPlane = aGPlane->Pln().Position();
00120     aWPlane = GEOMImpl_IMeasureOperations::GetPosition(aShape);
00121   }
00122   gp_Trsf aTrans;
00123   aTrans.SetTransformation(aWPlane);
00124   aTrans.Invert();
00125   BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
00126   aShape = aTransformation.Shape();
00127 
00128   if (aShape.IsNull())
00129     return 0;
00130 
00131   // set the function result
00132   aFunction->SetValue(aShape);
00133 
00134   log.SetTouched(Label());
00135 
00136   return 1;
00137 }
00138 
00139 
00140 //=======================================================================
00141 //function :  GEOMImpl_SketcherDriver_Type_
00142 //purpose  :
00143 //=======================================================================
00144 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SketcherDriver_Type_()
00145 {
00146 
00147   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00148   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00149   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00150   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00151   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00152   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00153 
00154 
00155   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00156   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SketcherDriver",
00157                                                          sizeof(GEOMImpl_SketcherDriver),
00158                                                          1,
00159                                                          (Standard_Address)_Ancestors,
00160                                                          (Standard_Address)NULL);
00161 
00162   return _aType;
00163 }
00164 
00165 //=======================================================================
00166 //function : DownCast
00167 //purpose  :
00168 //=======================================================================
00169 const Handle(GEOMImpl_SketcherDriver) Handle(GEOMImpl_SketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00170 {
00171   Handle(GEOMImpl_SketcherDriver) _anOtherObject;
00172 
00173   if (!AnObject.IsNull()) {
00174      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SketcherDriver))) {
00175        _anOtherObject = Handle(GEOMImpl_SketcherDriver)((Handle(GEOMImpl_SketcherDriver)&)AnObject);
00176      }
00177   }
00178 
00179   return _anOtherObject ;
00180 }