Salome HOME
Fixed bug in method GetReferncedObject that caused a crash in case if the reference...
[modules/geom.git] / src / GEOM_I / GEOM_IBlocksOperations_i.cc
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include <Standard_Stream.hxx>
21
22 #include "GEOM_IBlocksOperations_i.hh"
23
24 #include "utilities.h"
25 #include "OpUtil.hxx"
26 #include "Utils_ExceptHandlers.hxx"
27
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
30
31 #include <TColStd_HSequenceOfTransient.hxx>
32 #include <TColStd_HArray1OfInteger.hxx>
33
34 //=============================================================================
35 /*!
36  *   constructor:
37  */
38 //=============================================================================
39 GEOM_IBlocksOperations_i::GEOM_IBlocksOperations_i (PortableServer::POA_ptr thePOA,
40                                                     GEOM::GEOM_Gen_ptr theEngine,
41                                                     ::GEOMImpl_IBlocksOperations* theImpl)
42 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
43 {
44   MESSAGE("GEOM_IBlocksOperations_i::GEOM_IBlocksOperations_i");
45 }
46
47 //=============================================================================
48 /*!
49  *  destructor
50  */
51 //=============================================================================
52 GEOM_IBlocksOperations_i::~GEOM_IBlocksOperations_i()
53 {
54   MESSAGE("GEOM_IBlocksOperations_i::~GEOM_IBlocksOperations_i");
55 }
56
57
58 //=============================================================================
59 /*!
60  *  MakeQuad
61  */
62 //=============================================================================
63 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeQuad
64                (GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2,
65                 GEOM::GEOM_Object_ptr theEdge3, GEOM::GEOM_Object_ptr theEdge4)
66 {
67   GEOM::GEOM_Object_var aGEOMObject;
68
69   //Set a not done flag
70   GetOperations()->SetNotDone();
71
72   if (theEdge1 == NULL || theEdge2 == NULL ||
73       theEdge3 == NULL || theEdge4 == NULL) return aGEOMObject._retn();
74
75   //Get the reference edges
76   Handle(GEOM_Object) anEdge1 = GetOperations()->GetEngine()->GetObject
77     (theEdge1->GetStudyID(), theEdge1->GetEntry());
78   Handle(GEOM_Object) anEdge2 = GetOperations()->GetEngine()->GetObject
79     (theEdge2->GetStudyID(), theEdge2->GetEntry());
80   Handle(GEOM_Object) anEdge3 = GetOperations()->GetEngine()->GetObject
81     (theEdge3->GetStudyID(), theEdge3->GetEntry());
82   Handle(GEOM_Object) anEdge4 = GetOperations()->GetEngine()->GetObject
83     (theEdge4->GetStudyID(), theEdge4->GetEntry());
84
85   if (anEdge1.IsNull() || anEdge2.IsNull() ||
86       anEdge3.IsNull() || anEdge4.IsNull()) return aGEOMObject._retn();
87
88   //Create the Face
89   Handle(GEOM_Object) anObject =
90     GetOperations()->MakeQuad(anEdge1, anEdge2, anEdge3, anEdge4);
91   if (!GetOperations()->IsDone() || anObject.IsNull())
92     return aGEOMObject._retn();
93
94   return GetObject(anObject);
95 }
96
97 //=============================================================================
98 /*!
99  *  MakeQuad2Edges
100  */
101 //=============================================================================
102 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeQuad2Edges
103                (GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2)
104 {
105   GEOM::GEOM_Object_var aGEOMObject;
106
107   //Set a not done flag
108   GetOperations()->SetNotDone();
109
110   if (theEdge1 == NULL || theEdge2 == NULL) return aGEOMObject._retn();
111
112   //Get the reference edges
113   Handle(GEOM_Object) anEdge1 = GetOperations()->GetEngine()->GetObject
114     (theEdge1->GetStudyID(), theEdge1->GetEntry());
115   Handle(GEOM_Object) anEdge2 = GetOperations()->GetEngine()->GetObject
116     (theEdge2->GetStudyID(), theEdge2->GetEntry());
117
118   if (anEdge1.IsNull() || anEdge2.IsNull()) return aGEOMObject._retn();
119
120   //Create the Face
121   Handle(GEOM_Object) anObject =
122     GetOperations()->MakeQuad2Edges(anEdge1, anEdge2);
123   if (!GetOperations()->IsDone() || anObject.IsNull())
124     return aGEOMObject._retn();
125
126   return GetObject(anObject);
127 }
128
129 //=============================================================================
130 /*!
131  *  MakeQuad4Vertices
132  */
133 //=============================================================================
134 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeQuad4Vertices
135                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
136                        GEOM::GEOM_Object_ptr thePnt3, GEOM::GEOM_Object_ptr thePnt4)
137 {
138   GEOM::GEOM_Object_var aGEOMObject;
139
140   //Set a not done flag
141   GetOperations()->SetNotDone();
142
143   if (thePnt1 == NULL || thePnt2 == NULL ||
144       thePnt3 == NULL || thePnt4 == NULL) return aGEOMObject._retn();
145
146   //Get the reference points
147   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
148     (thePnt1->GetStudyID(), thePnt1->GetEntry());
149   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
150     (thePnt2->GetStudyID(), thePnt2->GetEntry());
151   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
152     (thePnt3->GetStudyID(), thePnt3->GetEntry());
153   Handle(GEOM_Object) aPnt4 = GetOperations()->GetEngine()->GetObject
154     (thePnt4->GetStudyID(), thePnt4->GetEntry());
155
156   if (aPnt1.IsNull() || aPnt2.IsNull() ||
157       aPnt3.IsNull() || aPnt4.IsNull()) return aGEOMObject._retn();
158
159   //Create the Face
160   Handle(GEOM_Object) anObject =
161     GetOperations()->MakeQuad4Vertices(aPnt1, aPnt2, aPnt3, aPnt4);
162   if (!GetOperations()->IsDone() || anObject.IsNull())
163     return aGEOMObject._retn();
164
165   return GetObject(anObject);
166 }
167
168 //=============================================================================
169 /*!
170  *  MakeHexa
171  */
172 //=============================================================================
173 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeHexa
174                (GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2,
175                 GEOM::GEOM_Object_ptr theFace3, GEOM::GEOM_Object_ptr theFace4,
176                 GEOM::GEOM_Object_ptr theFace5, GEOM::GEOM_Object_ptr theFace6)
177 {
178   GEOM::GEOM_Object_var aGEOMObject;
179
180   //Set a not done flag
181   GetOperations()->SetNotDone();
182
183   if (theFace1 == NULL || theFace2 == NULL ||
184       theFace3 == NULL || theFace4 == NULL ||
185       theFace5 == NULL || theFace6 == NULL) return aGEOMObject._retn();
186
187   //Get the reference Faces
188   Handle(GEOM_Object) anFace1 = GetOperations()->GetEngine()->GetObject
189     (theFace1->GetStudyID(), theFace1->GetEntry());
190   Handle(GEOM_Object) anFace2 = GetOperations()->GetEngine()->GetObject
191     (theFace2->GetStudyID(), theFace2->GetEntry());
192   Handle(GEOM_Object) anFace3 = GetOperations()->GetEngine()->GetObject
193     (theFace3->GetStudyID(), theFace3->GetEntry());
194   Handle(GEOM_Object) anFace4 = GetOperations()->GetEngine()->GetObject
195     (theFace4->GetStudyID(), theFace4->GetEntry());
196   Handle(GEOM_Object) anFace5 = GetOperations()->GetEngine()->GetObject
197     (theFace5->GetStudyID(), theFace5->GetEntry());
198   Handle(GEOM_Object) anFace6 = GetOperations()->GetEngine()->GetObject
199     (theFace6->GetStudyID(), theFace6->GetEntry());
200
201   if (anFace1.IsNull() || anFace2.IsNull() ||
202       anFace3.IsNull() || anFace4.IsNull() ||
203       anFace5.IsNull() || anFace6.IsNull()) return aGEOMObject._retn();
204
205   //Create the Face
206   Handle(GEOM_Object) anObject = GetOperations()->MakeHexa
207     (anFace1, anFace2, anFace3, anFace4, anFace5, anFace6);
208   if (!GetOperations()->IsDone() || anObject.IsNull())
209     return aGEOMObject._retn();
210
211   return GetObject(anObject);
212 }
213
214 //=============================================================================
215 /*!
216  *  MakeHexa2Faces
217  */
218 //=============================================================================
219 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeHexa2Faces
220                (GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2)
221 {
222   GEOM::GEOM_Object_var aGEOMObject;
223
224   //Set a not done flag
225   GetOperations()->SetNotDone();
226
227   if (theFace1 == NULL || theFace2 == NULL) return aGEOMObject._retn();
228
229   //Get the reference Faces
230   Handle(GEOM_Object) anFace1 = GetOperations()->GetEngine()->GetObject
231     (theFace1->GetStudyID(), theFace1->GetEntry());
232   Handle(GEOM_Object) anFace2 = GetOperations()->GetEngine()->GetObject
233     (theFace2->GetStudyID(), theFace2->GetEntry());
234
235   if (anFace1.IsNull() || anFace2.IsNull()) return aGEOMObject._retn();
236
237   //Create the Face
238   Handle(GEOM_Object) anObject =
239     GetOperations()->MakeHexa2Faces(anFace1, anFace2);
240   if (!GetOperations()->IsDone() || anObject.IsNull())
241     return aGEOMObject._retn();
242
243   return GetObject(anObject);
244 }
245
246 //=============================================================================
247 /*!
248  *  MakeBlockCompound
249  */
250 //=============================================================================
251 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeBlockCompound
252                                             (GEOM::GEOM_Object_ptr theCompound)
253 {
254   GEOM::GEOM_Object_var aGEOMObject;
255
256   //Set a not done flag
257   GetOperations()->SetNotDone();
258
259   if (theCompound == NULL) return aGEOMObject._retn();
260
261   //Get the reference Compound
262   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
263     (theCompound->GetStudyID(), theCompound->GetEntry());
264
265   if (aCompound.IsNull()) return aGEOMObject._retn();
266
267   //Create the Blocks Compound
268   Handle(GEOM_Object) anObject =
269     GetOperations()->MakeBlockCompound(aCompound);
270   if (!GetOperations()->IsDone() || anObject.IsNull())
271     return aGEOMObject._retn();
272
273   return GetObject(anObject);
274 }
275
276 //=============================================================================
277 /*!
278  *  GetPoint
279  */
280 //=============================================================================
281 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetPoint (GEOM::GEOM_Object_ptr theShape,
282                                                           const CORBA::Double   theX,
283                                                           const CORBA::Double   theY,
284                                                           const CORBA::Double   theZ,
285                                                           const CORBA::Double   theEpsilon)
286 {
287   GEOM::GEOM_Object_var aGEOMObject;
288
289   //Set a not done flag
290   GetOperations()->SetNotDone();
291
292   if (theShape == NULL) return aGEOMObject._retn();
293
294   //Get the reference Objects
295   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
296     (theShape->GetStudyID(), theShape->GetEntry());
297
298   if (aShape.IsNull()) return aGEOMObject._retn();
299
300   //Create the Point
301   Handle(GEOM_Object) anObject =
302     GetOperations()->GetPoint(aShape, theX, theY, theZ, theEpsilon);
303   if (!GetOperations()->IsDone() || anObject.IsNull())
304     return aGEOMObject._retn();
305
306   return GetObject(anObject);
307 }
308
309 //=============================================================================
310 /*!
311  *  GetEdge
312  */
313 //=============================================================================
314 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetEdge (GEOM::GEOM_Object_ptr theShape,
315                                                          GEOM::GEOM_Object_ptr thePoint1,
316                                                          GEOM::GEOM_Object_ptr thePoint2)
317 {
318   GEOM::GEOM_Object_var aGEOMObject;
319
320   //Set a not done flag
321   GetOperations()->SetNotDone();
322
323   if (theShape == NULL ||
324       thePoint1 == NULL || thePoint2 == NULL) return aGEOMObject._retn();
325
326   //Get the reference Objects
327   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
328     (theShape->GetStudyID(), theShape->GetEntry());
329   Handle(GEOM_Object) aPoint1 = GetOperations()->GetEngine()->GetObject
330     (thePoint1->GetStudyID(), thePoint1->GetEntry());
331   Handle(GEOM_Object) aPoint2 = GetOperations()->GetEngine()->GetObject
332     (thePoint2->GetStudyID(), thePoint2->GetEntry());
333
334   if (aShape.IsNull() ||
335       aPoint1.IsNull() || aPoint2.IsNull()) return aGEOMObject._retn();
336
337   //Create the Point
338   Handle(GEOM_Object) anObject =
339     GetOperations()->GetEdge(aShape, aPoint1, aPoint2);
340   if (!GetOperations()->IsDone() || anObject.IsNull())
341     return aGEOMObject._retn();
342
343   return GetObject(anObject);
344 }
345
346 //=============================================================================
347 /*!
348  *  GetEdgeNearPoint
349  */
350 //=============================================================================
351 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetEdgeNearPoint (GEOM::GEOM_Object_ptr theShape,
352                                                                   GEOM::GEOM_Object_ptr thePoint)
353 {
354   GEOM::GEOM_Object_var aGEOMObject;
355
356   //Set a not done flag
357   GetOperations()->SetNotDone();
358
359   if (theShape == NULL || thePoint == NULL) return aGEOMObject._retn();
360
361   //Get the reference Objects
362   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
363     (theShape->GetStudyID(), theShape->GetEntry());
364   Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
365     (thePoint->GetStudyID(), thePoint->GetEntry());
366
367   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
368
369   //Create the Edge
370   Handle(GEOM_Object) anObject =
371     GetOperations()->GetEdgeNearPoint(aShape, aPoint);
372   if (!GetOperations()->IsDone() || anObject.IsNull())
373     return aGEOMObject._retn();
374
375   return GetObject(anObject);
376 }
377
378 //=============================================================================
379 /*!
380  *  GetFaceByPoints
381  */
382 //=============================================================================
383 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByPoints
384                                               (GEOM::GEOM_Object_ptr theShape,
385                                                GEOM::GEOM_Object_ptr thePoint1,
386                                                GEOM::GEOM_Object_ptr thePoint2,
387                                                GEOM::GEOM_Object_ptr thePoint3,
388                                                GEOM::GEOM_Object_ptr thePoint4)
389 {
390   GEOM::GEOM_Object_var aGEOMObject;
391
392   //Set a not done flag
393   GetOperations()->SetNotDone();
394
395   if (theShape == NULL ||
396       thePoint1 == NULL || thePoint2 == NULL ||
397       thePoint3 == NULL || thePoint4 == NULL) return aGEOMObject._retn();
398
399   //Get the reference Objects
400   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
401     (theShape->GetStudyID(), theShape->GetEntry());
402   Handle(GEOM_Object) aPoint1 = GetOperations()->GetEngine()->GetObject
403     (thePoint1->GetStudyID(), thePoint1->GetEntry());
404   Handle(GEOM_Object) aPoint2 = GetOperations()->GetEngine()->GetObject
405     (thePoint2->GetStudyID(), thePoint2->GetEntry());
406   Handle(GEOM_Object) aPoint3 = GetOperations()->GetEngine()->GetObject
407     (thePoint3->GetStudyID(), thePoint3->GetEntry());
408   Handle(GEOM_Object) aPoint4 = GetOperations()->GetEngine()->GetObject
409     (thePoint4->GetStudyID(), thePoint4->GetEntry());
410
411   if (aShape.IsNull() ||
412       aPoint1.IsNull() || aPoint2.IsNull() ||
413       aPoint3.IsNull() || aPoint4.IsNull()) return aGEOMObject._retn();
414
415   //Create the Face
416   Handle(GEOM_Object) anObject =
417     GetOperations()->GetFaceByPoints(aShape, aPoint1, aPoint2, aPoint3, aPoint4);
418   if (!GetOperations()->IsDone() || anObject.IsNull())
419     return aGEOMObject._retn();
420
421   return GetObject(anObject);
422 }
423
424 //=============================================================================
425 /*!
426  *  GetFaceByEdges
427  */
428 //=============================================================================
429 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByEdges
430                                                (GEOM::GEOM_Object_ptr theShape,
431                                                 GEOM::GEOM_Object_ptr theEdge1,
432                                                 GEOM::GEOM_Object_ptr theEdge2)
433 {
434   GEOM::GEOM_Object_var aGEOMObject;
435
436   //Set a not done flag
437   GetOperations()->SetNotDone();
438
439   if (theShape == NULL ||
440       theEdge1 == NULL || theEdge2 == NULL) return aGEOMObject._retn();
441
442   //Get the reference Objects
443   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
444     (theShape->GetStudyID(), theShape->GetEntry());
445   Handle(GEOM_Object) anEdge1 = GetOperations()->GetEngine()->GetObject
446     (theEdge1->GetStudyID(), theEdge1->GetEntry());
447   Handle(GEOM_Object) anEdge2 = GetOperations()->GetEngine()->GetObject
448     (theEdge2->GetStudyID(), theEdge2->GetEntry());
449
450   if (aShape.IsNull() ||
451       anEdge1.IsNull() || anEdge2.IsNull()) return aGEOMObject._retn();
452
453   //Create the Face
454   Handle(GEOM_Object) anObject =
455     GetOperations()->GetFaceByEdges(aShape, anEdge1, anEdge2);
456   if (!GetOperations()->IsDone() || anObject.IsNull())
457     return aGEOMObject._retn();
458
459   return GetObject(anObject);
460 }
461
462 //=============================================================================
463 /*!
464  *  GetOppositeFace
465  */
466 //=============================================================================
467 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetOppositeFace (GEOM::GEOM_Object_ptr theShape,
468                                                                  GEOM::GEOM_Object_ptr theFace)
469 {
470   GEOM::GEOM_Object_var aGEOMObject;
471
472   //Set a not done flag
473   GetOperations()->SetNotDone();
474
475   if (theShape == NULL || theFace == NULL) return aGEOMObject._retn();
476
477   //Get the reference Objects
478   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
479     (theShape->GetStudyID(), theShape->GetEntry());
480   Handle(GEOM_Object) aFace = GetOperations()->GetEngine()->GetObject
481     (theFace->GetStudyID(), theFace->GetEntry());
482
483   if (aShape.IsNull() || aFace.IsNull()) return aGEOMObject._retn();
484
485   //Create the Face
486   Handle(GEOM_Object) anObject =
487     GetOperations()->GetOppositeFace(aShape, aFace);
488   if (!GetOperations()->IsDone() || anObject.IsNull())
489     return aGEOMObject._retn();
490
491   return GetObject(anObject);
492 }
493
494 //=============================================================================
495 /*!
496  *  GetFaceNearPoint
497  */
498 //=============================================================================
499 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceNearPoint (GEOM::GEOM_Object_ptr theShape,
500                                                                   GEOM::GEOM_Object_ptr thePoint)
501 {
502   GEOM::GEOM_Object_var aGEOMObject;
503
504   //Set a not done flag
505   GetOperations()->SetNotDone();
506
507   if (theShape == NULL || thePoint == NULL) return aGEOMObject._retn();
508
509   //Get the reference Objects
510   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
511     (theShape->GetStudyID(), theShape->GetEntry());
512   Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
513     (thePoint->GetStudyID(), thePoint->GetEntry());
514
515   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
516
517   //Create the Face
518   Handle(GEOM_Object) anObject =
519     GetOperations()->GetFaceNearPoint(aShape, aPoint);
520   if (!GetOperations()->IsDone() || anObject.IsNull())
521     return aGEOMObject._retn();
522
523   return GetObject(anObject);
524 }
525
526 //=============================================================================
527 /*!
528  *  GetFaceByNormale
529  */
530 //=============================================================================
531 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByNormale (GEOM::GEOM_Object_ptr theShape,
532                                                                   GEOM::GEOM_Object_ptr theVector)
533 {
534   GEOM::GEOM_Object_var aGEOMObject;
535
536   //Set a not done flag
537   GetOperations()->SetNotDone();
538
539   if (theShape == NULL || theVector == NULL) return aGEOMObject._retn();
540
541   //Get the reference Objects
542   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
543     (theShape->GetStudyID(), theShape->GetEntry());
544   Handle(GEOM_Object) aVector = GetOperations()->GetEngine()->GetObject
545     (theVector->GetStudyID(), theVector->GetEntry());
546
547   if (aShape.IsNull() || aVector.IsNull()) return aGEOMObject._retn();
548
549   //Create the Face
550   Handle(GEOM_Object) anObject =
551     GetOperations()->GetFaceByNormale(aShape, aVector);
552   if (!GetOperations()->IsDone() || anObject.IsNull())
553     return aGEOMObject._retn();
554
555   return GetObject(anObject);
556 }
557
558 //=============================================================================
559 /*!
560  *  ExplodeCompoundOfBlocks
561  */
562 //=============================================================================
563 GEOM::ListOfGO* GEOM_IBlocksOperations_i::ExplodeCompoundOfBlocks
564                                           (GEOM::GEOM_Object_ptr theCompound,
565                                            const CORBA::Long     theMinNbFaces,
566                                            const CORBA::Long     theMaxNbFaces)
567 {
568   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
569
570   //Set a not done flag
571   GetOperations()->SetNotDone();
572
573   if (theCompound == NULL) return aSeq._retn();
574
575   //Get the reference Compound
576   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
577     (theCompound->GetStudyID(), theCompound->GetEntry());
578
579   if (aCompound.IsNull()) return aSeq._retn();
580
581   //Explode
582   Handle(TColStd_HSequenceOfTransient) aHSeq =
583     GetOperations()->ExplodeCompoundOfBlocks(aCompound, theMinNbFaces, theMaxNbFaces);
584   if (!GetOperations()->IsDone() || aHSeq.IsNull())
585     return aSeq._retn();
586
587   Standard_Integer aLength = aHSeq->Length();
588   aSeq->length(aLength);
589   for (Standard_Integer i = 1; i <= aLength; i++)
590     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
591
592   return aSeq._retn();
593 }
594
595 //=============================================================================
596 /*!
597  *  IsCompoundOfBlocks
598  */
599 //=============================================================================
600 CORBA::Boolean GEOM_IBlocksOperations_i::IsCompoundOfBlocks
601                                           (GEOM::GEOM_Object_ptr theCompound,
602                                            const CORBA::Long     theMinNbFaces,
603                                            const CORBA::Long     theMaxNbFaces,
604                                            CORBA::Long&          theNbBlocks)
605 {
606   theNbBlocks = 0;
607   CORBA::Boolean isComp = false;
608
609   //Set a not done flag
610   GetOperations()->SetNotDone();
611
612   if (theCompound == NULL) return isComp;
613
614   //Get the reference Compound
615   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
616     (theCompound->GetStudyID(), theCompound->GetEntry());
617
618   if (aCompound.IsNull()) return isComp;
619
620   //Check
621   Standard_Integer nbBlocks = 0;
622   isComp = GetOperations()->IsCompoundOfBlocks(aCompound,
623                                                theMinNbFaces,
624                                                theMaxNbFaces,
625                                                nbBlocks);
626   if (!GetOperations()->IsDone())
627     return isComp;
628
629   theNbBlocks = nbBlocks;
630   return isComp;
631 }
632
633 //=============================================================================
634 /*!
635  *  CheckCompoundOfBlocks
636  */
637 //=============================================================================
638 CORBA::Boolean GEOM_IBlocksOperations_i::CheckCompoundOfBlocks
639                                           (GEOM::GEOM_Object_ptr theCompound,
640                                            GEOM::GEOM_IBlocksOperations::BCErrors_out theErrors)
641 {
642   CORBA::Boolean isComp = false;
643
644   //Set a not done flag
645   GetOperations()->SetNotDone();
646
647   if (theCompound == NULL) return isComp;
648
649   //Get the reference Compound
650   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
651     (theCompound->GetStudyID(), theCompound->GetEntry());
652
653   if (aCompound.IsNull()) return isComp;
654
655   //Check
656   list<GEOMImpl_IBlocksOperations::BCError> errList;
657   isComp = GetOperations()->CheckCompoundOfBlocks(aCompound, errList);
658   if (!GetOperations()->IsDone())
659     return isComp;
660
661   const int nbErr = errList.size();
662   GEOM::GEOM_IBlocksOperations::BCErrors_var anErrArray =
663     new GEOM::GEOM_IBlocksOperations::BCErrors();
664   anErrArray->length(nbErr);
665
666   // fill the local CORBA array with values from lists
667   list<GEOMImpl_IBlocksOperations::BCError>::iterator errIt = errList.begin();
668   int i = 0;
669   for (; errIt != errList.end(); i++, errIt++) {
670     GEOM::GEOM_IBlocksOperations::BCError_var anError =
671       new GEOM::GEOM_IBlocksOperations::BCError();
672
673     GEOMImpl_IBlocksOperations::BCError errStruct = *errIt;
674
675     switch (errStruct.error) {
676     case GEOMImpl_IBlocksOperations::NOT_BLOCK:
677       anError->error = GEOM::GEOM_IBlocksOperations::NOT_BLOCK;
678       break;
679     case GEOMImpl_IBlocksOperations::EXTRA_EDGE:
680       anError->error = GEOM::GEOM_IBlocksOperations::EXTRA_EDGE;
681       break;
682     case GEOMImpl_IBlocksOperations::INVALID_CONNECTION:
683       anError->error = GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION;
684       break;
685     case GEOMImpl_IBlocksOperations::NOT_CONNECTED:
686       anError->error = GEOM::GEOM_IBlocksOperations::NOT_CONNECTED;
687       break;
688     case GEOMImpl_IBlocksOperations::NOT_GLUED:
689       anError->error = GEOM::GEOM_IBlocksOperations::NOT_GLUED;
690       break;
691     default:
692       break;
693     }
694
695     list<int> sshList = errStruct.incriminated;
696     GEOM::ListOfLong_var anIncrims = new GEOM::ListOfLong();
697     anIncrims->length(sshList.size());
698
699     list<int>::iterator sshIt = sshList.begin();
700     int jj = 0;
701     for (; sshIt != sshList.end(); jj++, sshIt++) {
702       anIncrims[jj] = *sshIt;
703     }
704
705     anError->incriminated = anIncrims;
706
707     anErrArray[i] = anError;
708   }
709
710   // initialize out-parameter with local array
711   theErrors = anErrArray._retn();
712
713   return isComp;
714 }
715
716 //=============================================================================
717 /*!
718  *  PrintBCErrors
719  */
720 //=============================================================================
721 char* GEOM_IBlocksOperations_i::PrintBCErrors
722                       (GEOM::GEOM_Object_ptr theCompound,
723                        const GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
724 {
725   //Get the reference Compound
726   if (theCompound == NULL) return NULL;
727   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
728     (theCompound->GetStudyID(), theCompound->GetEntry());
729   if (aCompound.IsNull()) return NULL;
730
731   // Convert the errors sequence
732   list<GEOMImpl_IBlocksOperations::BCError> anErrors;
733   int nbErr = theErrors.length();
734   int ie = 0;
735   for (; ie < nbErr; ie++) {
736     const GEOM::GEOM_IBlocksOperations::BCError err = theErrors[ie];
737     const GEOM::GEOM_IBlocksOperations::BCErrorType typ = err.error;
738     const GEOM::ListOfLong incrims = err.incriminated;
739
740     GEOMImpl_IBlocksOperations::BCError errStruct;
741     switch (typ) {
742     case GEOM::GEOM_IBlocksOperations::NOT_BLOCK:
743       errStruct.error = GEOMImpl_IBlocksOperations::NOT_BLOCK;
744       break;
745     case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE:
746       errStruct.error = GEOMImpl_IBlocksOperations::EXTRA_EDGE;
747       break;
748     case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION:
749       errStruct.error = GEOMImpl_IBlocksOperations::INVALID_CONNECTION;
750       break;
751     case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED:
752       errStruct.error = GEOMImpl_IBlocksOperations::NOT_CONNECTED;
753       break;
754     case GEOM::GEOM_IBlocksOperations::NOT_GLUED:
755       errStruct.error = GEOMImpl_IBlocksOperations::NOT_GLUED;
756       break;
757     default:
758       break;
759     }
760
761     int ii = 0;
762     int aLen = incrims.length();
763     for (; ii < aLen; ii++) {
764       errStruct.incriminated.push_back(incrims[ii]);
765     }
766
767     anErrors.push_back(errStruct);
768   }
769
770   TCollection_AsciiString aDescr = GetOperations()->PrintBCErrors(aCompound, anErrors);
771   return CORBA::string_dup(aDescr.ToCString());    
772 }
773
774 //=============================================================================
775 /*!
776  *  RemoveExtraEdges
777  */
778 //=============================================================================
779 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::RemoveExtraEdges (GEOM::GEOM_Object_ptr theShape)
780 {
781   GEOM::GEOM_Object_var aGEOMObject;
782
783   //Set a not done flag
784   GetOperations()->SetNotDone();
785
786   if (theShape == NULL) return aGEOMObject._retn();
787
788   //Get the reference Objects
789   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
790     (theShape->GetStudyID(), theShape->GetEntry());
791
792   if (aShape.IsNull()) return aGEOMObject._retn();
793
794   //Get the result
795   Handle(GEOM_Object) anObject =
796     GetOperations()->RemoveExtraEdges(aShape);
797   if (!GetOperations()->IsDone() || anObject.IsNull())
798     return aGEOMObject._retn();
799
800   return GetObject(anObject);
801 }
802
803 //=============================================================================
804 /*!
805  *  CheckAndImprove
806  */
807 //=============================================================================
808 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::CheckAndImprove (GEOM::GEOM_Object_ptr theCompound)
809 {
810   GEOM::GEOM_Object_var aGEOMObject;
811
812   //Set a not done flag
813   GetOperations()->SetNotDone();
814
815   if (theCompound == NULL) return aGEOMObject._retn();
816
817   //Get the reference Objects
818   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
819     (theCompound->GetStudyID(), theCompound->GetEntry());
820
821   if (aCompound.IsNull()) return aGEOMObject._retn();
822
823   //Get the result
824   Handle(GEOM_Object) anObject =
825     GetOperations()->CheckAndImprove(aCompound);
826   if (!GetOperations()->IsDone() || anObject.IsNull())
827     return aGEOMObject._retn();
828
829   return GetObject(anObject);
830 }
831
832 //=============================================================================
833 /*!
834  *  GetBlockNearPoint
835  */
836 //=============================================================================
837 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetBlockNearPoint (GEOM::GEOM_Object_ptr theCompound,
838                                                                    GEOM::GEOM_Object_ptr thePoint)
839 {
840   GEOM::GEOM_Object_var aGEOMObject;
841
842   //Set a not done flag
843   GetOperations()->SetNotDone();
844
845   if (theCompound == NULL || thePoint == NULL) return aGEOMObject._retn();
846
847   //Get the reference Objects
848   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
849     (theCompound->GetStudyID(), theCompound->GetEntry());
850   Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
851     (thePoint->GetStudyID(), thePoint->GetEntry());
852
853   if (aCompound.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
854
855   //Get the block
856   Handle(GEOM_Object) anObject =
857     GetOperations()->GetBlockNearPoint(aCompound, aPoint);
858   if (!GetOperations()->IsDone() || anObject.IsNull())
859     return aGEOMObject._retn();
860
861   return GetObject(anObject);
862 }
863
864 //=============================================================================
865 /*!
866  *  GetBlockByParts
867  */
868 //=============================================================================
869 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetBlockByParts (GEOM::GEOM_Object_ptr theCompound,
870                                                                  const GEOM::ListOfGO& theParts)
871 {
872   GEOM::GEOM_Object_var aGEOMObject;
873
874   //Set a not done flag
875   GetOperations()->SetNotDone();
876
877   if (theCompound == NULL) return aGEOMObject._retn();
878
879   //Get the reference Compound
880   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
881     (theCompound->GetStudyID(), theCompound->GetEntry());
882
883   if (aCompound.IsNull()) return aGEOMObject._retn();
884
885   //Get the parts
886   int ind, aLen;
887   Handle(TColStd_HSequenceOfTransient) aParts = new TColStd_HSequenceOfTransient;
888
889   aLen = theParts.length();
890   for (ind = 0; ind < aLen; ind++) {
891     if (theParts[ind] == NULL) return aGEOMObject._retn();
892     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
893       (theParts[ind]->GetStudyID(), theParts[ind]->GetEntry());
894     if (aSh.IsNull()) return aGEOMObject._retn();
895     aParts->Append(aSh);
896   }
897
898   //Get the Block
899   Handle(GEOM_Object) anObject =
900     GetOperations()->GetBlockByParts(aCompound, aParts);
901   if (!GetOperations()->IsDone() || anObject.IsNull())
902     return aGEOMObject._retn();
903
904   return GetObject(anObject);
905 }
906
907 //=============================================================================
908 /*!
909  *  GetBlocksByParts
910  */
911 //=============================================================================
912 GEOM::ListOfGO* GEOM_IBlocksOperations_i::GetBlocksByParts (GEOM::GEOM_Object_ptr theCompound,
913                                                             const GEOM::ListOfGO& theParts)
914 {
915   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
916
917   //Set a not done flag
918   GetOperations()->SetNotDone();
919
920   if (theCompound == NULL) return aSeq._retn();
921
922   //Get the reference Compound
923   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
924     (theCompound->GetStudyID(), theCompound->GetEntry());
925
926   if (aCompound.IsNull()) return aSeq._retn();
927
928   //Get the parts
929   int ind, aLen;
930   Handle(TColStd_HSequenceOfTransient) aParts = new TColStd_HSequenceOfTransient;
931
932   aLen = theParts.length();
933   for (ind = 0; ind < aLen; ind++) {
934     if (theParts[ind] == NULL) return aSeq._retn();
935     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
936       (theParts[ind]->GetStudyID(), theParts[ind]->GetEntry());
937     if (aSh.IsNull()) return aSeq._retn();
938     aParts->Append(aSh);
939   }
940
941   //Get the Block
942   Handle(TColStd_HSequenceOfTransient) aHSeq =
943     GetOperations()->GetBlocksByParts(aCompound, aParts);
944   if (!GetOperations()->IsDone() || aHSeq.IsNull())
945     return aSeq._retn();
946
947   Standard_Integer aLength = aHSeq->Length();
948   aSeq->length(aLength);
949   for (Standard_Integer i = 1; i <= aLength; i++)
950     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
951
952   return aSeq._retn();
953 }
954
955 //=============================================================================
956 /*!
957  *  MakeMultiTransformation1D
958  */
959 //=============================================================================
960 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeMultiTransformation1D
961                                               (GEOM::GEOM_Object_ptr theBlock,
962                                                const CORBA::Long     theDirFace1,
963                                                const CORBA::Long     theDirFace2,
964                                                const CORBA::Long     theNbTimes)
965 {
966   GEOM::GEOM_Object_var aGEOMObject;
967
968    //Set a not done flag
969   GetOperations()->SetNotDone();
970
971   if (theBlock == NULL) return aGEOMObject._retn();
972
973    //Get the object itself and the vector of translation
974    Handle(GEOM_Object) aBasicObject = GetOperations()->GetEngine()->GetObject
975      (theBlock->GetStudyID(), theBlock->GetEntry());
976
977    if (aBasicObject.IsNull()) return aGEOMObject._retn();
978
979    //Perform the transformation
980    Handle(GEOM_Object) anObject = GetOperations()->MakeMultiTransformation1D
981      (aBasicObject, theDirFace1, theDirFace2, theNbTimes);
982    if (!GetOperations()->IsDone() || anObject.IsNull())  return aGEOMObject._retn();
983
984    return GetObject(anObject);
985 }
986
987 //=============================================================================
988 /*!
989  *  MakeMultiTransformation2D
990  */
991 //=============================================================================
992 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeMultiTransformation2D
993                                            (GEOM::GEOM_Object_ptr theBlock,
994                                             const CORBA::Long     theDirFace1U,
995                                             const CORBA::Long     theDirFace2U,
996                                             const CORBA::Long     theNbTimesU,
997                                             const CORBA::Long     theDirFace1V,
998                                             const CORBA::Long     theDirFace2V,
999                                             const CORBA::Long     theNbTimesV)
1000 {
1001   GEOM::GEOM_Object_var aGEOMObject;
1002
1003   //Set a not done flag
1004   GetOperations()->SetNotDone();
1005
1006   if (theBlock == NULL) return aGEOMObject._retn();
1007
1008   //Get the object itself
1009   Handle(GEOM_Object) aBasicObject = GetOperations()->GetEngine()->GetObject
1010     (theBlock->GetStudyID(), theBlock->GetEntry());
1011
1012   if (aBasicObject.IsNull()) return aGEOMObject._retn();
1013
1014   //Perform the transformation
1015   Handle(GEOM_Object) anObject = GetOperations()->MakeMultiTransformation2D
1016     (aBasicObject,
1017      theDirFace1U, theDirFace2U, theNbTimesU,
1018      theDirFace1V, theDirFace2V, theNbTimesV);
1019   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
1020
1021   return GetObject(anObject);
1022 }
1023
1024 //=============================================================================
1025 /*!
1026  *  Propagate
1027  */
1028 //=============================================================================
1029 GEOM::ListOfGO* GEOM_IBlocksOperations_i::Propagate (GEOM::GEOM_Object_ptr theShape)
1030 {
1031   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1032
1033   //Set a not done flag
1034   GetOperations()->SetNotDone();
1035
1036   if (theShape == NULL) return aSeq._retn();
1037
1038   //Get the reference Shape
1039   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1040     (theShape->GetStudyID(), theShape->GetEntry());
1041
1042   if (aShape.IsNull()) return aSeq._retn();
1043
1044   //Get the Propagation chains
1045   Handle(TColStd_HSequenceOfTransient) aHSeq =
1046     GetOperations()->Propagate(aShape);
1047   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1048     return aSeq._retn();
1049
1050   Standard_Integer aLength = aHSeq->Length();
1051   aSeq->length(aLength);
1052   for (Standard_Integer i = 1; i <= aLength; i++)
1053     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
1054
1055   return aSeq._retn();
1056 }