Salome HOME
Update copyright
[modules/geom.git] / src / GEOMImpl / GEOMImpl_CopyDriver.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include <GEOMImpl_CopyDriver.hxx>
26 #include <GEOMImpl_ICopy.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
29
30 #include <BRep_Tool.hxx>
31 #include <gp_Pnt.hxx>
32 #include <TopoDS.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TopAbs.hxx>
36 #include <TNaming_CopyShape.hxx>
37 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
38
39 //=======================================================================
40 //function : GetID
41 //purpose  :
42 //======================================================================= 
43 const Standard_GUID& GEOMImpl_CopyDriver::GetID()
44 {
45   static Standard_GUID aCopyDriver("FF1BBB53-5D14-4df2-980B-3A668264EA16");
46   return aCopyDriver; 
47 }
48
49
50 //=======================================================================
51 //function : GEOMImpl_CopyDriver
52 //purpose  : 
53 //=======================================================================
54 GEOMImpl_CopyDriver::GEOMImpl_CopyDriver() 
55 {
56 }
57
58 //=======================================================================
59 //function : Execute
60 //purpose  :
61 //======================================================================= 
62 Standard_Integer GEOMImpl_CopyDriver::Execute(TFunction_Logbook& log) const
63 {
64   if (Label().IsNull()) return 0;    
65   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
66
67   Standard_Integer aType = aFunction->GetType();
68
69   GEOMImpl_ICopy aCI (aFunction);
70   TopoDS_Shape aCopy;
71   
72   if(aType == COPY_WITH_REF) {
73   
74     Handle(GEOM_Function) aRefFunction = aCI.GetOriginal();
75     if (aRefFunction.IsNull()) return 0;
76     TopoDS_Shape anOriginal = aRefFunction->GetValue();
77
78     TColStd_IndexedDataMapOfTransientTransient aMap;
79   
80     TNaming_CopyShape::CopyTool(anOriginal, aMap, aCopy);
81   }
82   else if(aType == COPY_WITHOUT_REF) {
83     aCopy = aFunction->GetValue();
84   }
85   
86   if (aCopy.IsNull()) return 0;
87
88   aFunction->SetValue(aCopy);
89
90   log.SetTouched(Label()); 
91
92   return 1;    
93 }
94
95
96 //=======================================================================
97 //function :  GEOMImpl_CopyDriver_Type_
98 //purpose  :
99 //======================================================================= 
100 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CopyDriver_Type_()
101 {
102
103   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
104   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
105   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
106   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
107   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
108   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
109  
110
111   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
112   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CopyDriver",
113                                                          sizeof(GEOMImpl_CopyDriver),
114                                                          1,
115                                                          (Standard_Address)_Ancestors,
116                                                          (Standard_Address)NULL);
117
118   return _aType;
119 }
120
121 //=======================================================================
122 //function : DownCast
123 //purpose  :
124 //======================================================================= 
125 const Handle(GEOMImpl_CopyDriver) Handle(GEOMImpl_CopyDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
126 {
127   Handle(GEOMImpl_CopyDriver) _anOtherObject;
128
129   if (!AnObject.IsNull()) {
130      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CopyDriver))) {
131        _anOtherObject = Handle(GEOMImpl_CopyDriver)((Handle(GEOMImpl_CopyDriver)&)AnObject);
132      }
133   }
134
135   return _anOtherObject ;
136 }