Salome HOME
Merge from V6_main (04/10/2012)
[modules/geom.git] / src / GEOM_I / GEOM_IBlocksOperations_i.cc
1 // Copyright (C) 2007-2012  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  *  GetVertexNearPoint
274  */
275 //=============================================================================
276 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetVertexNearPoint
277                                                 (GEOM::GEOM_Object_ptr theShape,
278                                                  GEOM::GEOM_Object_ptr thePoint)
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) aPoint = GetObjectImpl(thePoint);
288   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
289
290   // Create the Point
291   Handle(GEOM_Object) anObject =
292     GetOperations()->GetVertexNearPoint(aShape, aPoint);
293   if (!GetOperations()->IsDone() || anObject.IsNull())
294     return aGEOMObject._retn();
295
296   return GetObject(anObject);
297 }
298
299 //=============================================================================
300 /*!
301  *  GetEdge
302  */
303 //=============================================================================
304 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetEdge (GEOM::GEOM_Object_ptr theShape,
305                                                          GEOM::GEOM_Object_ptr thePoint1,
306                                                          GEOM::GEOM_Object_ptr thePoint2)
307 {
308   GEOM::GEOM_Object_var aGEOMObject;
309
310   //Set a not done flag
311   GetOperations()->SetNotDone();
312
313   //Get the reference Objects
314   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
315   Handle(GEOM_Object) aPoint1 = GetObjectImpl(thePoint1);
316   Handle(GEOM_Object) aPoint2 = GetObjectImpl(thePoint2);
317
318   if (aShape.IsNull() ||
319       aPoint1.IsNull() || aPoint2.IsNull()) return aGEOMObject._retn();
320
321   //Create the Point
322   Handle(GEOM_Object) anObject =
323     GetOperations()->GetEdge(aShape, aPoint1, aPoint2);
324   if (!GetOperations()->IsDone() || anObject.IsNull())
325     return aGEOMObject._retn();
326
327   return GetObject(anObject);
328 }
329
330 //=============================================================================
331 /*!
332  *  GetEdgeNearPoint
333  */
334 //=============================================================================
335 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetEdgeNearPoint (GEOM::GEOM_Object_ptr theShape,
336                                                                   GEOM::GEOM_Object_ptr thePoint)
337 {
338   GEOM::GEOM_Object_var aGEOMObject;
339
340   //Set a not done flag
341   GetOperations()->SetNotDone();
342
343   //Get the reference Objects
344   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
345   Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
346
347   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
348
349   //Create the Edge
350   Handle(GEOM_Object) anObject =
351     GetOperations()->GetEdgeNearPoint(aShape, aPoint);
352   if (!GetOperations()->IsDone() || anObject.IsNull())
353     return aGEOMObject._retn();
354
355   return GetObject(anObject);
356 }
357
358 //=============================================================================
359 /*!
360  *  GetFaceByPoints
361  */
362 //=============================================================================
363 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByPoints
364                                               (GEOM::GEOM_Object_ptr theShape,
365                                                GEOM::GEOM_Object_ptr thePoint1,
366                                                GEOM::GEOM_Object_ptr thePoint2,
367                                                GEOM::GEOM_Object_ptr thePoint3,
368                                                GEOM::GEOM_Object_ptr thePoint4)
369 {
370   GEOM::GEOM_Object_var aGEOMObject;
371
372   //Set a not done flag
373   GetOperations()->SetNotDone();
374
375   //Get the reference Objects
376   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
377   Handle(GEOM_Object) aPoint1 = GetObjectImpl(thePoint1);
378   Handle(GEOM_Object) aPoint2 = GetObjectImpl(thePoint2);
379   Handle(GEOM_Object) aPoint3 = GetObjectImpl(thePoint3);
380   Handle(GEOM_Object) aPoint4 = GetObjectImpl(thePoint4);
381
382   if (aShape.IsNull() ||
383       aPoint1.IsNull() || aPoint2.IsNull() ||
384       aPoint3.IsNull() || aPoint4.IsNull()) return aGEOMObject._retn();
385
386   //Create the Face
387   Handle(GEOM_Object) anObject =
388     GetOperations()->GetFaceByPoints(aShape, aPoint1, aPoint2, aPoint3, aPoint4);
389   if (!GetOperations()->IsDone() || anObject.IsNull())
390     return aGEOMObject._retn();
391
392   return GetObject(anObject);
393 }
394
395 //=============================================================================
396 /*!
397  *  GetFaceByEdges
398  */
399 //=============================================================================
400 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByEdges
401                                                (GEOM::GEOM_Object_ptr theShape,
402                                                 GEOM::GEOM_Object_ptr theEdge1,
403                                                 GEOM::GEOM_Object_ptr theEdge2)
404 {
405   GEOM::GEOM_Object_var aGEOMObject;
406
407   //Set a not done flag
408   GetOperations()->SetNotDone();
409
410   //Get the reference Objects
411   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
412   Handle(GEOM_Object) anEdge1 = GetObjectImpl(theEdge1);
413   Handle(GEOM_Object) anEdge2 = GetObjectImpl(theEdge2);
414
415   if (aShape.IsNull() ||
416       anEdge1.IsNull() || anEdge2.IsNull()) return aGEOMObject._retn();
417
418   //Create the Face
419   Handle(GEOM_Object) anObject =
420     GetOperations()->GetFaceByEdges(aShape, anEdge1, anEdge2);
421   if (!GetOperations()->IsDone() || anObject.IsNull())
422     return aGEOMObject._retn();
423
424   return GetObject(anObject);
425 }
426
427 //=============================================================================
428 /*!
429  *  GetOppositeFace
430  */
431 //=============================================================================
432 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetOppositeFace (GEOM::GEOM_Object_ptr theShape,
433                                                                  GEOM::GEOM_Object_ptr theFace)
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) aFace = GetObjectImpl(theFace);
443
444   if (aShape.IsNull() || aFace.IsNull()) return aGEOMObject._retn();
445
446   //Create the Face
447   Handle(GEOM_Object) anObject =
448     GetOperations()->GetOppositeFace(aShape, aFace);
449   if (!GetOperations()->IsDone() || anObject.IsNull())
450     return aGEOMObject._retn();
451
452   return GetObject(anObject);
453 }
454
455 //=============================================================================
456 /*!
457  *  GetFaceNearPoint
458  */
459 //=============================================================================
460 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceNearPoint (GEOM::GEOM_Object_ptr theShape,
461                                                                   GEOM::GEOM_Object_ptr thePoint)
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) aPoint = GetObjectImpl(thePoint);
471
472   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
473
474   //Create the Face
475   Handle(GEOM_Object) anObject =
476     GetOperations()->GetFaceNearPoint(aShape, aPoint);
477   if (!GetOperations()->IsDone() || anObject.IsNull())
478     return aGEOMObject._retn();
479
480   return GetObject(anObject);
481 }
482
483 //=============================================================================
484 /*!
485  *  GetFaceByNormale
486  */
487 //=============================================================================
488 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByNormale (GEOM::GEOM_Object_ptr theShape,
489                                                                   GEOM::GEOM_Object_ptr theVector)
490 {
491   GEOM::GEOM_Object_var aGEOMObject;
492
493   //Set a not done flag
494   GetOperations()->SetNotDone();
495
496   //Get the reference Objects
497   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
498   Handle(GEOM_Object) aVector = GetObjectImpl(theVector);
499
500   if (aShape.IsNull() || aVector.IsNull()) return aGEOMObject._retn();
501
502   //Create the Face
503   Handle(GEOM_Object) anObject =
504     GetOperations()->GetFaceByNormale(aShape, aVector);
505   if (!GetOperations()->IsDone() || anObject.IsNull())
506     return aGEOMObject._retn();
507
508   return GetObject(anObject);
509 }
510
511 //=============================================================================
512 /*!
513  *  GetShapesNearPoint
514  */
515 //=============================================================================
516 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetShapesNearPoint
517                       (GEOM::GEOM_Object_ptr theShape,
518                        GEOM::GEOM_Object_ptr thePoint,
519                        CORBA::Long           theShapeType,
520                        CORBA::Double         theTolerance)
521 {
522   GEOM::GEOM_Object_var aGEOMObject;
523
524   // Set a not done flag
525   GetOperations()->SetNotDone();
526
527   // Get the reference Objects
528   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
529   Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
530
531   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
532
533   // Create the Shape
534   Handle(GEOM_Object) anObject =
535     GetOperations()->GetShapesNearPoint(aShape, aPoint, theShapeType, theTolerance);
536   if (!GetOperations()->IsDone() || anObject.IsNull())
537     return aGEOMObject._retn();
538
539   return GetObject(anObject);
540 }
541
542 //=============================================================================
543 /*!
544  *  ExplodeCompoundOfBlocks
545  */
546 //=============================================================================
547 GEOM::ListOfGO* GEOM_IBlocksOperations_i::ExplodeCompoundOfBlocks
548                                           (GEOM::GEOM_Object_ptr theCompound,
549                                            const CORBA::Long     theMinNbFaces,
550                                            const CORBA::Long     theMaxNbFaces)
551 {
552   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
553
554   //Set a not done flag
555   GetOperations()->SetNotDone();
556
557   //Get the reference Compound
558   Handle(GEOM_Object) aCompound = GetObjectImpl(theCompound);
559   if (aCompound.IsNull()) return aSeq._retn();
560
561   //Explode
562   Handle(TColStd_HSequenceOfTransient) aHSeq =
563     GetOperations()->ExplodeCompoundOfBlocks(aCompound, theMinNbFaces, theMaxNbFaces);
564   if (!GetOperations()->IsDone() || aHSeq.IsNull())
565     return aSeq._retn();
566
567   Standard_Integer aLength = aHSeq->Length();
568   aSeq->length(aLength);
569   for (Standard_Integer i = 1; i <= aLength; i++)
570     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
571
572   return aSeq._retn();
573 }
574
575 //=============================================================================
576 /*!
577  *  IsCompoundOfBlocks
578  */
579 //=============================================================================
580 CORBA::Boolean GEOM_IBlocksOperations_i::IsCompoundOfBlocks
581                                           (GEOM::GEOM_Object_ptr theCompound,
582                                            const CORBA::Long     theMinNbFaces,
583                                            const CORBA::Long     theMaxNbFaces,
584                                            CORBA::Long&          theNbBlocks)
585 {
586   theNbBlocks = 0;
587   CORBA::Boolean isComp = false;
588
589   //Set a not done flag
590   GetOperations()->SetNotDone();
591
592   //Get the reference Compound
593   Handle(GEOM_Object) aCompound = GetObjectImpl(theCompound);
594   if (aCompound.IsNull()) return isComp;
595
596   //Check
597   Standard_Integer nbBlocks = 0;
598   isComp = GetOperations()->IsCompoundOfBlocks(aCompound,
599                                                theMinNbFaces,
600                                                theMaxNbFaces,
601                                                nbBlocks);
602   if (!GetOperations()->IsDone())
603     return isComp;
604
605   theNbBlocks = nbBlocks;
606   return isComp;
607 }
608
609 //=============================================================================
610 /*!
611  *  CheckCompoundOfBlocks
612  */
613 //=============================================================================
614 CORBA::Boolean GEOM_IBlocksOperations_i::CheckCompoundOfBlocks
615                                           (GEOM::GEOM_Object_ptr theCompound,
616                                            GEOM::GEOM_IBlocksOperations::BCErrors_out theErrors)
617 {
618   CORBA::Boolean isComp = false;
619
620   //Set a not done flag
621   GetOperations()->SetNotDone();
622
623   //Get the reference Compound
624   Handle(GEOM_Object) aCompound = GetObjectImpl(theCompound);
625   if (aCompound.IsNull()) return isComp;
626
627   //Check
628   std::list<GEOMImpl_IBlocksOperations::BCError> errList;
629   isComp = GetOperations()->CheckCompoundOfBlocks(aCompound, errList);
630   if (!GetOperations()->IsDone())
631     return isComp;
632
633   const int nbErr = errList.size();
634   GEOM::GEOM_IBlocksOperations::BCErrors_var anErrArray =
635     new GEOM::GEOM_IBlocksOperations::BCErrors();
636   anErrArray->length(nbErr);
637
638   // fill the local CORBA array with values from lists
639   std::list<GEOMImpl_IBlocksOperations::BCError>::iterator errIt = errList.begin();
640   int i = 0;
641   for (; errIt != errList.end(); i++, errIt++) {
642     GEOM::GEOM_IBlocksOperations::BCError_var anError =
643       new GEOM::GEOM_IBlocksOperations::BCError();
644
645     GEOMImpl_IBlocksOperations::BCError errStruct = *errIt;
646
647     switch (errStruct.error) {
648     case GEOMImpl_IBlocksOperations::NOT_BLOCK:
649       anError->error = GEOM::GEOM_IBlocksOperations::NOT_BLOCK;
650       break;
651     case GEOMImpl_IBlocksOperations::EXTRA_EDGE:
652       anError->error = GEOM::GEOM_IBlocksOperations::EXTRA_EDGE;
653       break;
654     case GEOMImpl_IBlocksOperations::INVALID_CONNECTION:
655       anError->error = GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION;
656       break;
657     case GEOMImpl_IBlocksOperations::NOT_CONNECTED:
658       anError->error = GEOM::GEOM_IBlocksOperations::NOT_CONNECTED;
659       break;
660     case GEOMImpl_IBlocksOperations::NOT_GLUED:
661       anError->error = GEOM::GEOM_IBlocksOperations::NOT_GLUED;
662       break;
663     default:
664       break;
665     }
666
667     std::list<int> sshList = errStruct.incriminated;
668     GEOM::ListOfLong_var anIncrims = new GEOM::ListOfLong();
669     anIncrims->length(sshList.size());
670
671     std::list<int>::iterator sshIt = sshList.begin();
672     int jj = 0;
673     for (; sshIt != sshList.end(); jj++, sshIt++) {
674       anIncrims[jj] = *sshIt;
675     }
676
677     anError->incriminated = anIncrims;
678
679     anErrArray[i] = anError;
680   }
681
682   // initialize out-parameter with local array
683   theErrors = anErrArray._retn();
684
685   return isComp;
686 }
687
688 //=============================================================================
689 /*!
690  *  PrintBCErrors
691  */
692 //=============================================================================
693 char* GEOM_IBlocksOperations_i::PrintBCErrors
694                       (GEOM::GEOM_Object_ptr theCompound,
695                        const GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
696 {
697   //Get the reference Compound
698   Handle(GEOM_Object) aCompound = GetObjectImpl(theCompound);
699   if (aCompound.IsNull()) return NULL;
700
701   // Convert the errors sequence
702   std::list<GEOMImpl_IBlocksOperations::BCError> anErrors;
703   int nbErr = theErrors.length();
704   int ie = 0;
705   for (; ie < nbErr; ie++) {
706     const GEOM::GEOM_IBlocksOperations::BCError err = theErrors[ie];
707     const GEOM::GEOM_IBlocksOperations::BCErrorType typ = err.error;
708     const GEOM::ListOfLong incrims = err.incriminated;
709
710     GEOMImpl_IBlocksOperations::BCError errStruct;
711     switch (typ) {
712     case GEOM::GEOM_IBlocksOperations::NOT_BLOCK:
713       errStruct.error = GEOMImpl_IBlocksOperations::NOT_BLOCK;
714       break;
715     case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE:
716       errStruct.error = GEOMImpl_IBlocksOperations::EXTRA_EDGE;
717       break;
718     case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION:
719       errStruct.error = GEOMImpl_IBlocksOperations::INVALID_CONNECTION;
720       break;
721     case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED:
722       errStruct.error = GEOMImpl_IBlocksOperations::NOT_CONNECTED;
723       break;
724     case GEOM::GEOM_IBlocksOperations::NOT_GLUED:
725       errStruct.error = GEOMImpl_IBlocksOperations::NOT_GLUED;
726       break;
727     default:
728       break;
729     }
730
731     int ii = 0;
732     int aLen = incrims.length();
733     for (; ii < aLen; ii++) {
734       errStruct.incriminated.push_back(incrims[ii]);
735     }
736
737     anErrors.push_back(errStruct);
738   }
739
740   TCollection_AsciiString aDescr = GetOperations()->PrintBCErrors(aCompound, anErrors);
741   return CORBA::string_dup(aDescr.ToCString());
742 }
743
744 //=============================================================================
745 /*!
746  *  GetNonBlocks
747  */
748 //=============================================================================
749 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetNonBlocks
750                                       (GEOM::GEOM_Object_ptr theShape,
751                                        GEOM::GEOM_Object_out theNonQuads)
752 {
753   GEOM::GEOM_Object_var aGEOMObject;
754   GEOM::GEOM_Object_var aNonQuads;
755
756   theNonQuads = aNonQuads._retn();
757
758   //Set a not done flag
759   GetOperations()->SetNotDone();
760
761   //Get the reference Objects
762   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
763   if (aShape.IsNull()) return aGEOMObject._retn();
764
765   //Get the result
766   Handle(GEOM_Object) aFaces;
767   Handle(GEOM_Object) anObject = GetOperations()->GetNonBlocks(aShape, aFaces);
768   if (!GetOperations()->IsDone() || anObject.IsNull())
769     return aGEOMObject._retn();
770
771   if (!aFaces.IsNull())
772     theNonQuads = GetObject(aFaces);
773
774   return GetObject(anObject);
775 }
776
777 //=============================================================================
778 /*!
779  *  RemoveExtraEdges
780  */
781 //=============================================================================
782 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::RemoveExtraEdges
783                                       (GEOM::GEOM_Object_ptr theShape,
784                                        CORBA::Long           theOptimumNbFaces)
785 {
786   GEOM::GEOM_Object_var aGEOMObject;
787
788   //Set a not done flag
789   GetOperations()->SetNotDone();
790
791   //Get the reference Objects
792   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
793   if (aShape.IsNull()) return aGEOMObject._retn();
794
795   //Get the result
796   Handle(GEOM_Object) anObject = GetOperations()->RemoveExtraEdges(aShape, theOptimumNbFaces);
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   //Get the reference Objects
816   Handle(GEOM_Object) aCompound = GetObjectImpl(theCompound);
817   if (aCompound.IsNull()) return aGEOMObject._retn();
818
819   //Get the result
820   Handle(GEOM_Object) anObject =
821     GetOperations()->CheckAndImprove(aCompound);
822   if (!GetOperations()->IsDone() || anObject.IsNull())
823     return aGEOMObject._retn();
824
825   return GetObject(anObject);
826 }
827
828 //=============================================================================
829 /*!
830  *  GetBlockNearPoint
831  */
832 //=============================================================================
833 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetBlockNearPoint (GEOM::GEOM_Object_ptr theCompound,
834                                                                    GEOM::GEOM_Object_ptr thePoint)
835 {
836   GEOM::GEOM_Object_var aGEOMObject;
837
838   //Set a not done flag
839   GetOperations()->SetNotDone();
840
841   //Get the reference Objects
842   Handle(GEOM_Object) aCompound = GetObjectImpl(theCompound);
843   Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
844
845   if (aCompound.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
846
847   //Get the block
848   Handle(GEOM_Object) anObject =
849     GetOperations()->GetBlockNearPoint(aCompound, aPoint);
850   if (!GetOperations()->IsDone() || anObject.IsNull())
851     return aGEOMObject._retn();
852
853   return GetObject(anObject);
854 }
855
856 //=============================================================================
857 /*!
858  *  GetBlockByParts
859  */
860 //=============================================================================
861 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetBlockByParts (GEOM::GEOM_Object_ptr theCompound,
862                                                                  const GEOM::ListOfGO& theParts)
863 {
864   GEOM::GEOM_Object_var aGEOMObject;
865
866   //Set a not done flag
867   GetOperations()->SetNotDone();
868
869   //Get the reference Compound
870   Handle(GEOM_Object) aCompound = GetObjectImpl(theCompound);
871   if (aCompound.IsNull()) return aGEOMObject._retn();
872
873   //Get the parts
874   int ind, aLen;
875   Handle(TColStd_HSequenceOfTransient) aParts = new TColStd_HSequenceOfTransient;
876
877   aLen = theParts.length();
878   for (ind = 0; ind < aLen; ind++) {
879     Handle(GEOM_Object) aSh = GetObjectImpl(theParts[ind]);
880     if (aSh.IsNull()) return aGEOMObject._retn();
881     aParts->Append(aSh);
882   }
883
884   //Get the Block
885   Handle(GEOM_Object) anObject =
886     GetOperations()->GetBlockByParts(aCompound, aParts);
887   if (!GetOperations()->IsDone() || anObject.IsNull())
888     return aGEOMObject._retn();
889
890   return GetObject(anObject);
891 }
892
893 //=============================================================================
894 /*!
895  *  GetBlocksByParts
896  */
897 //=============================================================================
898 GEOM::ListOfGO* GEOM_IBlocksOperations_i::GetBlocksByParts (GEOM::GEOM_Object_ptr theCompound,
899                                                             const GEOM::ListOfGO& theParts)
900 {
901   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
902
903   //Set a not done flag
904   GetOperations()->SetNotDone();
905
906   //Get the reference Compound
907   Handle(GEOM_Object) aCompound = GetObjectImpl(theCompound);
908   if (aCompound.IsNull()) return aSeq._retn();
909
910   //Get the parts
911   int ind, aLen;
912   Handle(TColStd_HSequenceOfTransient) aParts = new TColStd_HSequenceOfTransient;
913
914   aLen = theParts.length();
915   for (ind = 0; ind < aLen; ind++) {
916     Handle(GEOM_Object) aSh = GetObjectImpl(theParts[ind]);
917     if (aSh.IsNull()) return aSeq._retn();
918     aParts->Append(aSh);
919   }
920
921   //Get the Block
922   Handle(TColStd_HSequenceOfTransient) aHSeq =
923     GetOperations()->GetBlocksByParts(aCompound, aParts);
924   if (!GetOperations()->IsDone() || aHSeq.IsNull())
925     return aSeq._retn();
926
927   Standard_Integer aLength = aHSeq->Length();
928   aSeq->length(aLength);
929   for (Standard_Integer i = 1; i <= aLength; i++)
930     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
931
932   return aSeq._retn();
933 }
934
935 //=============================================================================
936 /*!
937  *  MakeMultiTransformation1D
938  */
939 //=============================================================================
940 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeMultiTransformation1D
941                                               (GEOM::GEOM_Object_ptr theBlock,
942                                                const CORBA::Long     theDirFace1,
943                                                const CORBA::Long     theDirFace2,
944                                                const CORBA::Long     theNbTimes)
945 {
946   GEOM::GEOM_Object_var aGEOMObject;
947
948   //Set a not done flag
949   GetOperations()->SetNotDone();
950
951   //Get the object itself and the vector of translation
952   Handle(GEOM_Object) aBasicObject = GetObjectImpl(theBlock);
953   if (aBasicObject.IsNull()) return aGEOMObject._retn();
954
955   //Perform the transformation
956   Handle(GEOM_Object) anObject = GetOperations()->MakeMultiTransformation1D
957     (aBasicObject, theDirFace1, theDirFace2, theNbTimes);
958   if (!GetOperations()->IsDone() || anObject.IsNull())  return aGEOMObject._retn();
959
960   return GetObject(anObject);
961 }
962
963 //=============================================================================
964 /*!
965  *  MakeMultiTransformation2D
966  */
967 //=============================================================================
968 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeMultiTransformation2D
969                                            (GEOM::GEOM_Object_ptr theBlock,
970                                             const CORBA::Long     theDirFace1U,
971                                             const CORBA::Long     theDirFace2U,
972                                             const CORBA::Long     theNbTimesU,
973                                             const CORBA::Long     theDirFace1V,
974                                             const CORBA::Long     theDirFace2V,
975                                             const CORBA::Long     theNbTimesV)
976 {
977   GEOM::GEOM_Object_var aGEOMObject;
978
979   //Set a not done flag
980   GetOperations()->SetNotDone();
981
982   //Get the object itself
983   Handle(GEOM_Object) aBasicObject = GetObjectImpl(theBlock);
984   if (aBasicObject.IsNull()) return aGEOMObject._retn();
985
986   //Perform the transformation
987   Handle(GEOM_Object) anObject = GetOperations()->MakeMultiTransformation2D
988     (aBasicObject,
989      theDirFace1U, theDirFace2U, theNbTimesU,
990      theDirFace1V, theDirFace2V, theNbTimesV);
991   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
992
993   return GetObject(anObject);
994 }
995
996 //=============================================================================
997 /*!
998  *  Propagate
999  */
1000 //=============================================================================
1001 GEOM::ListOfGO* GEOM_IBlocksOperations_i::Propagate (GEOM::GEOM_Object_ptr theShape)
1002 {
1003   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1004
1005   //Set a not done flag
1006   GetOperations()->SetNotDone();
1007
1008   //Get the reference Shape
1009   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
1010   if (aShape.IsNull()) return aSeq._retn();
1011
1012   //Get the Propagation chains
1013   Handle(TColStd_HSequenceOfTransient) aHSeq =
1014     GetOperations()->Propagate(aShape);
1015   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1016     return aSeq._retn();
1017
1018   Standard_Integer aLength = aHSeq->Length();
1019   aSeq->length(aLength);
1020   for (Standard_Integer i = 1; i <= aLength; i++)
1021     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
1022
1023   return aSeq._retn();
1024 }