0023024: Update headers of OCCT files
[occt.git] / src / BOP / BOP_WireShell.cxx
1 // Created on: 2002-02-04
2 // Created by: Peter KURNEV
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21
22 #include <BOP_WireShell.ixx>
23
24 #include <Standard_Failure.hxx>
25 #include <Standard_ErrorHandler.hxx>
26
27 #include <TopAbs_ShapeEnum.hxx>
28
29 #include <BooleanOperations_ShapesDataStructure.hxx>
30
31 #include <BOPTColStd_Dump.hxx>
32
33 #include <BOPTools_DSFiller.hxx>
34 #include <BOPTools_PaveFiller.hxx>
35 #include <BOPTools_WireStateFiller.hxx>
36
37 #include <BOP_CorrectTolerances.hxx>
38
39 //=======================================================================
40 // function: BOP_WireShell::BOP_WireShell
41 // purpose: 
42 //=======================================================================
43 BOP_WireShell::BOP_WireShell()
44 {
45 }
46 //=======================================================================
47 // function: Destroy
48 // purpose: 
49 //=======================================================================
50   void BOP_WireShell::Destroy() 
51 {
52 }
53 //=======================================================================
54 // function: Do
55 // purpose: 
56 //=======================================================================
57   void BOP_WireShell::Do() 
58 {
59   myErrorStatus=0;
60   myIsDone=Standard_False;
61   //
62   // Filling the DS
63   BOPTools_DSFiller aDSFiller;
64   aDSFiller.SetShapes (myShape1, myShape2);
65   //
66   aDSFiller.Perform ();
67   //
68   DoWithFiller(aDSFiller);
69 }
70
71 //=======================================================================
72 // function: DoWithFiller
73 // purpose: 
74 //=======================================================================
75   void BOP_WireShell::DoWithFiller(const BOPTools_DSFiller& aDSFiller) 
76 {
77   myErrorStatus=0;
78   myIsDone=Standard_False;
79   //
80   myResultMap.Clear();
81   myModifiedMap.Clear();
82   //
83   myDSFiller=(BOPTools_DSFiller*) &aDSFiller;
84   //
85   try {
86     OCC_CATCH_SIGNALS
87
88     if(!myDSFiller->IsDone()) {
89       myErrorStatus = 1;
90       BOPTColStd_Dump::PrintMessage("DSFiller is invalid: Can not build result\n");
91       return;
92     }
93
94     Standard_Boolean bCheckTypes;
95     //
96     bCheckTypes=CheckArgTypes();
97     if (!bCheckTypes) {
98       myErrorStatus=10;
99       return;
100     }
101     //
102     Standard_Boolean bIsNewFiller;
103     bIsNewFiller=aDSFiller.IsNewFiller();
104     
105     if (bIsNewFiller) {
106       //
107       // Preparing the States
108       const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
109       BOPTools_WireStateFiller aStateFiller(aPaveFiller);
110       aStateFiller.Do();
111       
112       aDSFiller.SetNewFiller(!bIsNewFiller);
113     }
114     //
115     BuildResult();
116     //
117     BOP_CorrectTolerances::CorrectTolerances(myResult, 0.01);
118     //
119     FillModified();
120     myIsDone=Standard_True;
121   }
122   catch ( Standard_Failure ) {
123     myErrorStatus = 1;
124     BOPTColStd_Dump::PrintMessage("Can not build result\n");
125   }
126 }
127
128 //=======================================================================
129 // function: BuildResult
130 // purpose: 
131 //=======================================================================
132   void BOP_WireShell::BuildResult()
133 {
134   AddSplitPartsINOUT();
135   AddSplitPartsON();
136   //
137   MakeResult();
138 }
139
140 //=======================================================================
141 // function: CheckArgTypes
142 // purpose: 
143 //=======================================================================
144 Standard_Boolean BOP_WireShell::CheckArgTypes(const TopAbs_ShapeEnum theType1,
145                                               const TopAbs_ShapeEnum theType2,
146                                               const BOP_Operation theOperation) 
147 {
148   Standard_Boolean bFlag=Standard_False;
149   
150   //
151   if (theType1==TopAbs_WIRE && theType2==TopAbs_SHELL) {
152     if (theOperation==BOP_FUSE || theOperation==BOP_CUT21) {
153       return bFlag;
154     }
155   }
156   //
157   if (theType1==TopAbs_SHELL && theType2==TopAbs_WIRE) {
158     if (theOperation==BOP_FUSE || theOperation==BOP_CUT) {
159       return bFlag;
160     }
161   }
162   //
163   return !bFlag;
164 }
165
166
167 //=======================================================================
168 // function: CheckArgTypes
169 // purpose: 
170 //=======================================================================
171   Standard_Boolean BOP_WireShell::CheckArgTypes() const
172 {
173 //   Standard_Boolean bFlag=Standard_False;
174   
175   TopAbs_ShapeEnum aT1, aT2;
176   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
177
178   aT1=aDS.Object().ShapeType();
179   aT2=aDS.Tool().ShapeType();
180   //
181 //   if (aT1==TopAbs_WIRE && aT2==TopAbs_SHELL) {
182 //     if (myOperation==BOP_FUSE || myOperation==BOP_CUT21) {
183 //       return bFlag;
184 //     }
185 //   }
186 //   //
187 //   if (aT1==TopAbs_SHELL && aT2==TopAbs_WIRE) {
188 //     if (myOperation==BOP_FUSE || myOperation==BOP_CUT) {
189 //       return bFlag;
190 //     }
191 //   }
192 //   //
193 //   return !bFlag;
194   return CheckArgTypes(aT1, aT2, myOperation);
195 }