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