0028643: Coding rules - eliminate GCC compiler warnings -Wmisleading-indentation
[occt.git] / src / TPrsStd / TPrsStd_ConstraintTools.cxx
index 464896d..17e58e0 100644 (file)
 // Purpose:     Update AIS object from a TDataXtd_Constraint.
 // Modified     Mon 30 10:15:43 1998 by SZY
 
-
-#include <TPrsStd_ConstraintTools.ixx>
-
-#include <stdio.h>
-#include <UnitsAPI.hxx>
-#include <TCollection_ExtendedString.hxx>
-
-#include <TNaming_Tool.hxx>
-#include <TNaming_Iterator.hxx>
-#include <TNaming_NamedShape.hxx>
-#include <TDF_Label.hxx>
-#include <TDataStd_Real.hxx>
-#include <TDataStd_Name.hxx>
-#include <TDataXtd_Geometry.hxx>
-#include <TDF_Reference.hxx>
-
-
-#include <AIS_OffsetDimension.hxx>
-#include <AIS_LengthDimension.hxx>
-#include <AIS_ParallelRelation.hxx>
-#include <AIS_TangentRelation.hxx>
-#include <AIS_IdenticRelation.hxx>
 #include <AIS_AngleDimension.hxx>
-#include <AIS_RadiusDimension.hxx>
+#include <AIS_ConcentricRelation.hxx>
 #include <AIS_DiameterDimension.hxx>
+#include <AIS_EqualDistanceRelation.hxx>
+#include <AIS_EqualRadiusRelation.hxx>
 #include <AIS_FixRelation.hxx>
-#include <AIS_PerpendicularRelation.hxx>
-#include <AIS_ConcentricRelation.hxx>
-#include <AIS_SymmetricRelation.hxx>
-#include <AIS_MidPointRelation.hxx>
+#include <AIS_IdenticRelation.hxx>
 #include <AIS_InteractiveContext.hxx>
-#include <AIS_Drawer.hxx>
-#include <AIS_EqualRadiusRelation.hxx>
-#include <AIS_EqualDistanceRelation.hxx>
-#include <AIS_MinRadiusDimension.hxx> 
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_LengthDimension.hxx>
 #include <AIS_MaxRadiusDimension.hxx>
-
-#include <TopoDS.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Shape.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>
-
-#include <BRep_Tool.hxx>
+#include <AIS_MidPointRelation.hxx>
+#include <AIS_MinRadiusDimension.hxx>
+#include <AIS_OffsetDimension.hxx>
+#include <AIS_ParallelRelation.hxx>
+#include <AIS_PerpendicularRelation.hxx>
+#include <AIS_RadiusDimension.hxx>
+#include <AIS_Relation.hxx>
+#include <AIS_SymmetricRelation.hxx>
+#include <AIS_TangentRelation.hxx>
 #include <BRep_Builder.hxx>
-#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRep_Tool.hxx>
 #include <BRepAdaptor_Curve.hxx>
 #include <BRepAdaptor_Surface.hxx>
-
-#include <GeomAbs_SurfaceType.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <GC_MakePlane.hxx>
+#include <Geom_CartesianPoint.hxx>
+#include <Geom_Circle.hxx>
 #include <Geom_Geometry.hxx>
 #include <Geom_Line.hxx>
 #include <Geom_Plane.hxx>
-#include <Geom_CartesianPoint.hxx>
-#include <Geom_Circle.hxx>
-#include <gp_Pln.hxx>
-#include <gp_Dir.hxx>
+#include <GeomAbs_SurfaceType.hxx>
 #include <gp_Ax1.hxx>
+#include <gp_Cone.hxx>
+#include <gp_Cylinder.hxx>
+#include <gp_Dir.hxx>
 #include <gp_Lin.hxx>
+#include <gp_Pln.hxx>
 #include <gp_Pnt.hxx>
-#include <gp_Cylinder.hxx>
-#include <gp_Cone.hxx>
 #include <gp_Torus.hxx>
-#include <GC_MakePlane.hxx> 
-
-#include <Precision.hxx>
 #include <IntAna_QuadQuadGeo.hxx>
-
-#include <Standard_ProgramError.hxx>
+#include <Precision.hxx>
+#include <Prs3d_Drawer.hxx>
 #include <Standard_ErrorHandler.hxx>
-
+#include <Standard_ProgramError.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TDataStd_Name.hxx>
+#include <TDataStd_Real.hxx>
+#include <TDataXtd_Constraint.hxx>
+#include <TDataXtd_Geometry.hxx>
+#include <TDF_Label.hxx>
+#include <TDF_Reference.hxx>
+#include <TNaming_Iterator.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TNaming_Tool.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Vertex.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
+#include <TPrsStd_ConstraintTools.hxx>
+#include <UnitsAPI.hxx>
 
-#define BUC60846
-
+#include <stdio.h>
 static Standard_Boolean CheckShapesPair(const TopoDS_Shape& , const TopoDS_Shape& ); //ota
 
 //=======================================================================
@@ -124,21 +114,27 @@ static void FindExternalShape(const Handle(TDataXtd_Constraint)& aConst,
 //function : static GetGoodShape for planar constraint
 //purpose  : 
 //=======================================================================
-static void  GetGoodShape(TopoDS_Shape& shape)
+static void  GetGoodShape(TopoDS_Shape& theShape)
 {
-  switch (shape.ShapeType()) {
+  switch (theShape.ShapeType())
+  {
   case TopAbs_EDGE:
   case TopAbs_VERTEX: { return; }
   default:
     {
-      TopExp_Explorer EXP(shape,TopAbs_EDGE);
-      if (EXP.More()) {
-       shape = EXP.Current();
-       return;
+      TopExp_Explorer anExp (theShape,TopAbs_EDGE);
+      if (anExp.More())
+      {
+        theShape = anExp.Current();
+        return;
       }
-      else {
-       EXP.Init(shape,TopAbs_VERTEX);
-       if (EXP.More()) shape = EXP.Current();
+      else
+      {
+        anExp.Init (theShape, TopAbs_VERTEX);
+        if (anExp.More())
+        {
+          theShape = anExp.Current();
+        }
       }
     }
   }
@@ -231,180 +227,232 @@ void TPrsStd_ConstraintTools::UpdateOnlyValue(const Handle(TDataXtd_Constraint)&
 
 //=======================================================================
 //function : ComputeDistance
-//purpose  : Build an AIS_LengtDimension.
+//purpose  : Build an AIS_LengthDimension.
 //=======================================================================
-void TPrsStd_ConstraintTools::ComputeDistance (const Handle(TDataXtd_Constraint)& aConst,
-                                             Handle(AIS_InteractiveObject)& anAIS) 
+void TPrsStd_ConstraintTools::ComputeDistance (const Handle(TDataXtd_Constraint)& theConst,
+                                               Handle(AIS_InteractiveObject)&     theAIS)
 {
-  Standard_Integer nbgeom = aConst->NbGeometries();
-  if (nbgeom < 2) {
-#ifdef DEB
-    cout <<  "TPrsStd_ConstraintTools::ComputeDistance: at least 2 geometries are needed" << endl;
+  Standard_Integer aGeomNum = theConst->NbGeometries();
+
+  // Dimension is build on one or two shapes.
+  if (aGeomNum < 1 || aGeomNum > 2)
+  {
+#ifdef OCCT_DEBUG
+    cout <<  "TPrsStd_ConstraintTools::ComputeDistance: 1 or 2 geometries are needed" << endl;
 #endif
-    NullifyAIS(anAIS);
+    NullifyAIS(theAIS);
     return;
   }
-  TopoDS_Shape shape1,shape2,shape3 ;
-  Handle(Geom_Geometry) ageom3;
-  Standard_Boolean is_planar(aConst->IsPlanar()),is_directed(Standard_False);
-  AIS_TypeOfDist typedist = AIS_TOD_Unknown;
+
+  TopoDS_Shape aShape1, aShape2;
+  Handle(Geom_Geometry) aGeom3;
+  Standard_Boolean isPlanar (theConst->IsPlanar());
 
   // Get shapes and geometry
-  if (is_planar) {
-    if (nbgeom == 2)
-      GetShapesAndGeom (aConst,shape1,shape2,ageom3);
-    else
-      GetShapesAndGeom (aConst,shape1,shape2,shape3,ageom3);
+  if (aGeomNum == 1)
+  {
+    GetOneShape (theConst, aShape1);
+
+    if (aShape1.IsNull())
+    {
+      #ifdef OCCT_DEBUG
+      cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
+      #endif
+      NullifyAIS (theAIS);
+      return;
+    }
   }
-  else
-    GetTwoShapes (aConst,shape1,shape2);    
+  else //aGeomNum == 2
+  {
+    GetTwoShapes (theConst, aShape1, aShape2);
 
-  if (shape1.IsNull() || shape2.IsNull()) {
-#ifdef DEB
-    cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
-#endif
-    NullifyAIS(anAIS);
-    return;
+    if (aShape1.IsNull() || aShape2.IsNull())
+    {
+      #ifdef OCCT_DEBUG
+      cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
+      #endif
+      NullifyAIS (theAIS);
+      return;
+    }
   }
 
-  Handle(Geom_Plane) aplane;
-  if (is_planar) {
-    if (nbgeom != 2) {
-      is_directed = !shape3.IsNull();
-      if (!is_directed)  {
-#ifdef DEB
-       cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
-#endif
-       NullifyAIS(anAIS);
-       return;
-      }
+  // Get plane from constraint
+  Handle(Geom_Plane) aPlane;
+  if (isPlanar)
+  {
+    GetGeom (theConst, aGeom3);
+
+    GetGoodShape (aShape1);
+
+    if (aGeomNum == 2)
+    {
+      GetGoodShape (aShape2);
     }
 
-    GetGoodShape (shape1);
-    GetGoodShape (shape2);
+    aPlane = Handle(Geom_Plane)::DownCast (aGeom3);
+  }
 
-    aplane = Handle(Geom_Plane)::DownCast(ageom3);
-    if (aplane.IsNull()) {
-#ifdef DEB
-      cout << "TPrsStd_ConstraintTools::ComputeDistance : null plane" << endl;
-#endif
-      NullifyAIS(anAIS);
+  // Get custom value
+  Standard_Real aValue;
+  TCollection_ExtendedString aText;
+  ComputeTextAndValue (theConst, aValue, aText,Standard_False);
+
+  Standard_Boolean isFaces     = Standard_False;
+  Standard_Boolean isEdges     = Standard_False;
+  Standard_Boolean isEdgeFace  = Standard_False;
+  Standard_Boolean isVertices  = Standard_False;
+  Standard_Boolean isEdge      = Standard_False;
+
+  Standard_Boolean SaveDrw = Standard_False;
+  Handle(Prs3d_Drawer) aDrawer;
+  Handle(AIS_LengthDimension) aDim;
+
+  if (!theAIS.IsNull())
+  {
+    aDim = Handle(AIS_LengthDimension)::DownCast (theAIS);
+  }
+
+  // Check shapes for AIS dimension
+  if (aGeomNum == 1)
+  {
+    if (aShape1.ShapeType () != TopAbs_EDGE)
+    {
+      #ifdef OCCT_DEBUG
+      cout << "TPrsStd_ConstraintTools::ComputeDistance : shape should be edge" << endl;
+      #endif
+      NullifyAIS (theAIS);
       return;
     }
-    
-    if (is_directed) {
-      GetGoodShape(shape3);
-      const TopoDS_Edge& E = TopoDS::Edge(shape3);
-      BRepAdaptor_Curve CURVE(E);
-      Handle_Geom_Geometry aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
-      gp_Dir Dir = ((Handle(Geom_Line)&) aGeomGeometry)->Lin().Direction();
-      gp_Dir xdir(aplane->Pln().Position().XDirection());
-      if (Dir.IsParallel(xdir,Precision::Confusion()))
-       typedist = AIS_TOD_Horizontal;
-      else
-       typedist = AIS_TOD_Vertical;
-    }
+
+    isEdge = Standard_True;
   }
+  else // nbgeom == 2
+  {
+    isFaces      = IsFace (aShape1) && IsFace (aShape2);
 
-  Standard_Real val1;
-  TCollection_ExtendedString txt;
-  ComputeTextAndValue(aConst,val1,txt,Standard_False);
-  
-  //  Arguments de l'AIS
-  Standard_Boolean isface = IsFace(shape1) && IsFace(shape2);
-  Standard_Boolean isedgeface = (shape1.ShapeType () == TopAbs_FACE && 
-                                 shape2.ShapeType () == TopAbs_EDGE);
-  Standard_Boolean is2vertices =(shape1.ShapeType () == TopAbs_VERTEX &&                 //addition 1
-                                 shape2.ShapeType () == TopAbs_VERTEX);
-  if (!isface && !is_planar && !is2vertices)  {
-    // Recherche arguments pouvant convenir
-    if (shape1.ShapeType() == shape2.ShapeType())  {
-      TopoDS_Vertex  v1,v2,v3,v4;
-      if (shape1.ShapeType() == TopAbs_EDGE)  {
-       TopExp::Vertices (TopoDS::Edge(shape1),v1,v2);
-       TopExp::Vertices (TopoDS::Edge(shape2),v3,v4);
-      }
-      else
-      if (shape1.ShapeType() == TopAbs_WIRE)  {
-       TopExp::Vertices (TopoDS::Wire(shape1),v1,v2);
-       TopExp::Vertices (TopoDS::Wire(shape2),v3,v4);
-      }
-      shape1 = v1;
-      gp_Pnt P1 = BRep_Tool::Pnt(v1);
-      gp_Pnt P2 = BRep_Tool::Pnt(v3), P3 = BRep_Tool::Pnt(v4);
-      if (P1.Distance(P2) < P1.Distance(P3))  {
-       shape2 = v3;
-       gp_Ax2 ax2 (P1, gp_Dir (P2.XYZ() - P1.XYZ()));
-       aplane = new Geom_Plane (P1,ax2.XDirection());
-      }
-      else {
-       shape2 = v4;
-       gp_Ax2 ax2 (P1, gp_Dir (P3.XYZ() - P1.XYZ()));
-       aplane = new Geom_Plane (P1,ax2.XDirection());
+    isEdges      = (aShape1.ShapeType() == TopAbs_EDGE) && (aShape2.ShapeType() == TopAbs_EDGE);
+
+    isEdgeFace   = ((aShape1.ShapeType() == TopAbs_FACE) && (aShape2.ShapeType() == TopAbs_EDGE))
+                   || ((aShape1.ShapeType() == TopAbs_EDGE) && (aShape2.ShapeType() == TopAbs_FACE));
+
+    isVertices  = (aShape1.ShapeType() == TopAbs_VERTEX) && (aShape2.ShapeType() == TopAbs_VERTEX);
+
+    if (!isPlanar && !isFaces && !isEdges && !isVertices)
+    {
+      // Search suitable geometry for dimension
+      if (aShape1.ShapeType() == aShape2.ShapeType())
+      {
+        TopoDS_Vertex aV1, aV2, aV3, aV4;
+        if (aShape1.ShapeType() == TopAbs_WIRE)
+        {
+          TopExp::Vertices (TopoDS::Wire(aShape1), aV1, aV2);
+          TopExp::Vertices (TopoDS::Wire(aShape2), aV3, aV4);
+        }
+        aShape1 = aV1;
+        gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
+        gp_Pnt aP2 = BRep_Tool::Pnt(aV3);
+        gp_Pnt aP3 = BRep_Tool::Pnt (aV4);
+        if (aP1.Distance (aP2) < aP1.Distance (aP3))
+        {
+          aShape2 = aV3;
+          gp_Ax2 ax2 (aP1, gp_Dir (aP2.XYZ() - aP1.XYZ()));
+          aPlane = new Geom_Plane (aP1, ax2.XDirection());
+        }
+        else
+        {
+          aShape2 = aV4;
+          gp_Ax2 anAx2 (aP1, gp_Dir (aP3.XYZ() - aP1.XYZ()));
+          aPlane = new Geom_Plane (aP1, anAx2.XDirection());
+        }
       }
-    }
-    else  {
-      if (!isedgeface) {
-       NullifyAIS(anAIS);
-       return;
+      else if (!isEdgeFace)
+      {
+        NullifyAIS (theAIS);
+        return;
       }
     }
   }
 
-  //  Update de l'AIS
-  Handle(AIS_LengthDimension) ais;
-  Standard_Boolean SaveDrw = Standard_False;
-  Handle(AIS_Drawer) aDrawer;
+  // Check plane
+  Standard_Boolean isCheckPlane = (aDim.IsNull() && !isFaces) || isPlanar;
+  if ((isVertices || isEdges) && !isPlanar)
+  {
+    gp_Pnt aP1, aP2, aP3;
 
-  if (!anAIS.IsNull()) {
-    ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
+    if (isVertices)
+    {
+      aP1 = BRep_Tool::Pnt (TopoDS::Vertex (aShape1));
+      aP2 = BRep_Tool::Pnt (TopoDS::Vertex (aShape2));
+      aP3 = gp_Pnt (aP1.Y() - 1.0, aP2.X() + 1.0, 0.0);
+    }
+
+    if (isEdges)
+    {
+      TopoDS_Vertex  aV1, aV2, aV3, aV4;
+      TopExp::Vertices (TopoDS::Edge(aShape1), aV1, aV2);
+      TopExp::Vertices (TopoDS::Edge(aShape2), aV3, aV4);
+      aP1 = BRep_Tool::Pnt (aV1);
+      aP2 = BRep_Tool::Pnt (aV2);
+      aP3 = BRep_Tool::Pnt (aV3);
+    }
+
+    GC_MakePlane aPlaneMaker (aP1, aP2, aP3);
+    if (aPlaneMaker.IsDone() && !isPlanar)
+    {
+      aPlane = aPlaneMaker.Value();
+    }
+  }
+
+  if (isCheckPlane && aPlane.IsNull())
+  {
+    #ifdef OCCT_DEBUG
+    cout << "TPrsStd_ConstraintTools::ComputeDistance : null plane" << endl;
+    #endif
+    NullifyAIS (theAIS);
+    return;
   }
 
-  if (ais.IsNull())  {
-    if (is2vertices)  {                                        //addition 2
-      gp_Pnt P1 = BRep_Tool::Pnt( TopoDS::Vertex(shape1) );
-      gp_Pnt P2 = BRep_Tool::Pnt( TopoDS::Vertex(shape2) );
-      gp_Pnt P3(P1.Y()-1., P2.X()+1., 0.); 
-      GC_MakePlane mkPlane(P1, P2, P3); 
-      ais = new AIS_LengthDimension (P1, P2, mkPlane.Value()->Pln());
+  //  Update of AIS
+  if (aDim.IsNull())
+  {
+    if (isEdge)
+    {
+      aDim = new AIS_LengthDimension (GetEdge (aShape1), aPlane->Pln());
     }
-    else if (isface)
+    else if (isFaces)
     {
-      ais = new AIS_LengthDimension (GetFace(shape1),GetFace(shape2),aplane->Pln());
+      aDim = new AIS_LengthDimension (GetFace (aShape1), GetFace (aShape2));
     }
-    else if (isedgeface) {
-      ais = new AIS_LengthDimension (GetFace(shape1),GetEdge(shape2),aplane->Pln());
+    else
+    {
+      aDim = new AIS_LengthDimension (aShape1, aShape2, aPlane->Pln());
     }
-    else  {
-      ais = new AIS_LengthDimension (shape1,shape2,aplane->Pln());
+
+    if (SaveDrw)
+    {
+        aDim->SetAttributes (aDrawer);
     }
-    if( SaveDrw ) ais->SetAttributes(aDrawer);   
   }
-  else {
-    if (isface)
+  else
+  {
+    if (isEdge)
     {
-      ais->SetMeasuredGeometry (GetFace(shape1), GetFace(shape2));
+      aDim->SetMeasuredGeometry (GetEdge(aShape1), aPlane->Pln());
     }
     else
     {
-      ais->SetMeasuredShapes (shape1, shape2);
-    }
-    if (is2vertices)  {                     //addition 3
-      gp_Pnt P1 = BRep_Tool::Pnt( TopoDS::Vertex(shape1) );
-      gp_Pnt P2 = BRep_Tool::Pnt( TopoDS::Vertex(shape2) );
-      gp_Pnt P3(P1.Y()-1., P2.X()+1., 0.); 
-      GC_MakePlane mkPlane(P1, P2, P3); 
-      ais->SetCustomPlane( mkPlane.Value()->Pln() );
+      aDim->SetMeasuredShapes (aShape1, aShape2);
     }
 
-    ais->SetCustomValue       (val1);
+    aDim->SetCustomValue (aValue);
   }
-  
-  if (is_planar)
+
+  if (!aPlane.IsNull())
   {
-    ais->SetCustomPlane (aplane->Pln());
+    aDim->SetCustomPlane (aPlane->Pln());
   }
-  anAIS = ais;
+
+  theAIS = aDim;
 }
 
 //=======================================================================
@@ -416,7 +464,7 @@ void TPrsStd_ConstraintTools::ComputePerpendicular(const Handle(TDataXtd_Constra
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 2) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputePerpendicular: at leat two constraintes are needed" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -430,7 +478,7 @@ void TPrsStd_ConstraintTools::ComputePerpendicular(const Handle(TDataXtd_Constra
   if (is_planar) GetShapesAndGeom(aConst,shape1,shape2,ageom3);
   else GetTwoShapes(aConst,shape1,shape2); 
   if (shape1.IsNull() || shape2.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputePerpendicular : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -455,7 +503,7 @@ void TPrsStd_ConstraintTools::ComputePerpendicular(const Handle(TDataXtd_Constra
   if (is_planar) {
     Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
     if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputePerpendicular: nul plane" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -475,7 +523,7 @@ void TPrsStd_ConstraintTools::ComputeParallel(const Handle(TDataXtd_Constraint)&
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 2) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeParallel: at least 2 constraintes are needed" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -483,7 +531,7 @@ void TPrsStd_ConstraintTools::ComputeParallel(const Handle(TDataXtd_Constraint)&
   }
   
   if (!aConst->IsPlanar()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeParallel: must be a planar constraint" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -495,7 +543,7 @@ void TPrsStd_ConstraintTools::ComputeParallel(const Handle(TDataXtd_Constraint)&
   
   GetShapesAndGeom(aConst,shape1,shape2,ageom3);
   if (shape1.IsNull() || shape2.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeParallel : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -503,7 +551,7 @@ void TPrsStd_ConstraintTools::ComputeParallel(const Handle(TDataXtd_Constraint)&
   }
   Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
   if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeParallel: nul plane" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -536,7 +584,7 @@ void TPrsStd_ConstraintTools::ComputeSymmetry(const Handle(TDataXtd_Constraint)&
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 3) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraintes are needed" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -545,7 +593,7 @@ void TPrsStd_ConstraintTools::ComputeSymmetry(const Handle(TDataXtd_Constraint)&
 
   Standard_Boolean is_planar(aConst->IsPlanar());
   if (!is_planar) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -557,7 +605,7 @@ void TPrsStd_ConstraintTools::ComputeSymmetry(const Handle(TDataXtd_Constraint)&
   GetShapesAndGeom(aConst,shape1,shape2,shape3,ageom3);
 
   if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -568,7 +616,7 @@ void TPrsStd_ConstraintTools::ComputeSymmetry(const Handle(TDataXtd_Constraint)&
   GetGoodShape(shape3);
   Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
   if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -602,7 +650,7 @@ void TPrsStd_ConstraintTools::ComputeMidPoint(const Handle(TDataXtd_Constraint)&
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 3)
     {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraints are needed" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -612,7 +660,7 @@ void TPrsStd_ConstraintTools::ComputeMidPoint(const Handle(TDataXtd_Constraint)&
   Standard_Boolean is_planar(aConst->IsPlanar());
   if ( !is_planar )
     {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -625,7 +673,7 @@ void TPrsStd_ConstraintTools::ComputeMidPoint(const Handle(TDataXtd_Constraint)&
 
   if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull())
     {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -638,7 +686,7 @@ void TPrsStd_ConstraintTools::ComputeMidPoint(const Handle(TDataXtd_Constraint)&
   Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
   if (aplane.IsNull())
     {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -675,14 +723,14 @@ void TPrsStd_ConstraintTools::ComputeTangent (const Handle(TDataXtd_Constraint)&
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 2) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeTangent: at leat two constraintes are needed" << endl;
 #endif
     NullifyAIS(anAIS);
     return;
   }
   if (!aConst->IsPlanar()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeTangent: must be a planar constraint" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -693,7 +741,7 @@ void TPrsStd_ConstraintTools::ComputeTangent (const Handle(TDataXtd_Constraint)&
   
   GetShapesAndGeom(aConst,shape1,shape2,ageom3);
   if (shape1.IsNull() || shape2.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeTangent : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -703,7 +751,7 @@ void TPrsStd_ConstraintTools::ComputeTangent (const Handle(TDataXtd_Constraint)&
   GetGoodShape(shape2);
   Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
   if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeTangent: nul plane" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -748,7 +796,7 @@ void TPrsStd_ConstraintTools::ComputeAngleForOneFace (const Handle(TDataXtd_Cons
   
   GetOneShape( aConst, shape ); 
   if (shape.IsNull() ) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeAngleForOneFace : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -798,7 +846,7 @@ static Standard_Boolean CheckIsShapeCompound(TopoDS_Shape& shape, TopoDS_Face& a
        }
       }
   }
-#ifdef DEB
+#ifdef OCCT_DEBUG
   cout << "TPrsStd::Compute angle : Shape is not Compound or is Null" <<endl;
 #endif
   return (Standard_False);
@@ -815,7 +863,7 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 2) {
     if( nbgeom == 1 ) { ComputeAngleForOneFace( aConst, anAIS ); return; }
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeAngle: at least 2 constraints are needed" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -827,7 +875,7 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
   
   GetShapesAndGeom (aConst,shape1,shape2,ageom3);
   if (shape1.IsNull() || shape2.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeAngle : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -851,7 +899,7 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
        aFace    = TopoDS::Face(shape1);
       else
        if(!CheckIsShapeCompound(shape1, aFace)) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
        cout << "Compute angle : Geom type = " << shape1.ShapeType()
          << " non traite"<<endl;
 #endif
@@ -877,7 +925,7 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
       gp_Torus aTore = aSurfaFace.Torus();
       anax1aFace1 = aTore.Axis();  
     } else {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout<<"Compute angle"<<aTypeaFace<<" non traite"<<endl;
 #endif
       NullifyAIS(anAIS);
@@ -898,7 +946,7 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
        aFace    = TopoDS::Face(shape2); 
     else  
       if(!CheckIsShapeCompound(shape2, aFace)) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
        cout << "Compute angle : Geom type = " << shape2.ShapeType()
          << " non traite"<<endl;
 #endif
@@ -921,7 +969,7 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
       gp_Torus aTore = aSurfaFace.Torus();
       anax1aFace2 = aTore.Axis();  
     } else {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "Compute angle " << aTypeaFace << " non traite"<<endl;
 #endif
       NullifyAIS(anAIS);
@@ -938,7 +986,7 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
          Handle(Geom_Line) computedgeom3 = new Geom_Line (aLine);
          ageom3 = computedgeom3;
        } else {
-#ifdef DEB
+#ifdef OCCT_DEBUG
          cout<<"Compute angle insertection of planes failed"<<endl;
 #endif
          NullifyAIS(anAIS);
@@ -946,7 +994,7 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
        }
       } else {
        
-#ifdef DEB
+#ifdef OCCT_DEBUG
        cout<<"Compute angle faces are //"<<endl;
 #endif
        NullifyAIS(anAIS);
@@ -965,7 +1013,7 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
     if (ageom3->IsKind(STANDARD_TYPE(Geom_Plane))) isplan = Standard_True;
     else if (ageom3->IsKind(STANDARD_TYPE(Geom_Line))) isplan = Standard_False;
     else {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeAngle: unknown 3rd arg " << endl;
 #endif
       NullifyAIS(anAIS);
@@ -1019,11 +1067,11 @@ void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& a
     }
     ais->SetMeasuredGeometry (TopoDS::Face (shape1), TopoDS::Face (shape2));
     if (isplan)
-      ais->SetCustomPlane (((Handle(Geom_Plane)&) ageom3)->Pln());
+      ais->SetCustomPlane (Handle(Geom_Plane)::DownCast (ageom3)->Pln());
     else if (!isCurvilinear)
     {
       gp_Pln aPlane;
-      aPlane.SetAxis (((Handle(Geom_Line)&) ageom3)->Position());
+      aPlane.SetAxis (Handle(Geom_Line)::DownCast (ageom3)->Position());
       ais->SetCustomPlane (aPlane);
     }
   }
@@ -1040,10 +1088,10 @@ void TPrsStd_ConstraintTools::ComputeConcentric(const Handle(TDataXtd_Constraint
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 2) {
-    Standard_ProgramError::Raise ("TPrsStd_ConstraintTools::ComputeConcentric: at least 2 constraintes are needed");
+    throw Standard_ProgramError("TPrsStd_ConstraintTools::ComputeConcentric: at least 2 constraintes are needed");
   }
   if (!aConst->IsPlanar()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeConcentric: must be a planar constraint" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1054,7 +1102,7 @@ void TPrsStd_ConstraintTools::ComputeConcentric(const Handle(TDataXtd_Constraint
   
   GetShapesAndGeom(aConst,shape1,shape2,ageom3);
   if (shape1.IsNull() || shape2.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeConcentric : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1066,7 +1114,7 @@ void TPrsStd_ConstraintTools::ComputeConcentric(const Handle(TDataXtd_Constraint
 
 //ota : to allow concentric constraint display between vertex and edge
   if (shape1.ShapeType() != TopAbs_EDGE && shape2.ShapeType() != TopAbs_EDGE) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeConcentric: concentric between two vertexes : NOT DISPLAYED" << endl;;
 #endif
     NullifyAIS(anAIS);
@@ -1075,7 +1123,7 @@ void TPrsStd_ConstraintTools::ComputeConcentric(const Handle(TDataXtd_Constraint
 
   Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
   if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeConcentric: nul plane" << endl;;
 #endif
     NullifyAIS(anAIS);
@@ -1110,7 +1158,7 @@ void TPrsStd_ConstraintTools::ComputeRadius (const Handle(TDataXtd_Constraint)&
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 1) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeRadius: at least one constrainte is needed" << endl;    
 #endif
     NullifyAIS(anAIS);
@@ -1120,7 +1168,7 @@ void TPrsStd_ConstraintTools::ComputeRadius (const Handle(TDataXtd_Constraint)&
   TopoDS_Shape shape1 ;
   GetOneShape (aConst,shape1);
   if (shape1.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeRadius: null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1132,7 +1180,7 @@ void TPrsStd_ConstraintTools::ComputeRadius (const Handle(TDataXtd_Constraint)&
       shape1.ShapeType()==TopAbs_COMPSOLID ||
       shape1.ShapeType()==TopAbs_SOLID ||
       shape1.ShapeType()==TopAbs_SHELL ) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeRadius: not good shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1167,7 +1215,7 @@ void TPrsStd_ConstraintTools::ComputeRadius (const Handle(TDataXtd_Constraint)&
     GetGeom(aConst,ageom2);
     Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
     if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeRadius: nul plane" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -1187,7 +1235,7 @@ void TPrsStd_ConstraintTools::ComputeMinRadius (const Handle(TDataXtd_Constraint
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 1) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeMinRadius: at least one constrainte is needed" << endl;    
 #endif
     NullifyAIS(anAIS);
@@ -1197,7 +1245,7 @@ void TPrsStd_ConstraintTools::ComputeMinRadius (const Handle(TDataXtd_Constraint
   TopoDS_Shape shape1 ;
   GetOneShape (aConst,shape1);
   if (shape1.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeMinradius: null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1209,7 +1257,7 @@ void TPrsStd_ConstraintTools::ComputeMinRadius (const Handle(TDataXtd_Constraint
       shape1.ShapeType()==TopAbs_COMPSOLID ||
       shape1.ShapeType()==TopAbs_SOLID ||
       shape1.ShapeType()==TopAbs_SHELL ) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeMinRadius: not good shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1246,7 +1294,7 @@ void TPrsStd_ConstraintTools::ComputeMinRadius (const Handle(TDataXtd_Constraint
     GetGeom(aConst,ageom2);
     Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
     if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeMinRadius: nul plane" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -1266,7 +1314,7 @@ void TPrsStd_ConstraintTools::ComputeMaxRadius (const Handle(TDataXtd_Constraint
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 1) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: at least one constrainte is needed" << endl;    
 #endif
     NullifyAIS(anAIS);
@@ -1276,7 +1324,7 @@ void TPrsStd_ConstraintTools::ComputeMaxRadius (const Handle(TDataXtd_Constraint
   TopoDS_Shape shape1 ;
   GetOneShape (aConst,shape1);
   if (shape1.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeMaxradius: null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1288,7 +1336,7 @@ void TPrsStd_ConstraintTools::ComputeMaxRadius (const Handle(TDataXtd_Constraint
       shape1.ShapeType()==TopAbs_COMPSOLID ||
       shape1.ShapeType()==TopAbs_SOLID ||
       shape1.ShapeType()==TopAbs_SHELL ) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: not good shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1325,7 +1373,7 @@ void TPrsStd_ConstraintTools::ComputeMaxRadius (const Handle(TDataXtd_Constraint
     GetGeom(aConst,ageom2);
     Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
     if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: nul plane" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -1345,7 +1393,9 @@ void TPrsStd_ConstraintTools::ComputeEqualDistance(const Handle(TDataXtd_Constra
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 4) {
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeEqual: at least four geometries are needed" << endl;;
+#endif
       NullifyAIS(anAIS);
       return;
     }
@@ -1354,7 +1404,7 @@ void TPrsStd_ConstraintTools::ComputeEqualDistance(const Handle(TDataXtd_Constra
   GetShapesAndGeom(aConst, aShape1, aShape2, aShape3, aShape4, aGeom);
    if (aShape1.IsNull()||aShape2.IsNull()||
        aShape3.IsNull()||aShape4.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1368,7 +1418,7 @@ void TPrsStd_ConstraintTools::ComputeEqualDistance(const Handle(TDataXtd_Constra
   
   if (!CheckShapesPair(aShape1, aShape2) || 
       !CheckShapesPair(aShape3, aShape4)){
-#ifdef DEB
+#ifdef OCCT_DEBUG
        cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : at least one pair of shapes is incorrect"<<endl;
 #endif
        NullifyAIS(anAIS);
@@ -1382,7 +1432,7 @@ void TPrsStd_ConstraintTools::ComputeEqualDistance(const Handle(TDataXtd_Constra
  
   if (!IsPlanar || aPlane.IsNull()) {
     //create the plane
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout<< "The constraint plane is not assigned "<< endl;
 #endif
     NullifyAIS(anAIS);
@@ -1437,7 +1487,7 @@ static Standard_Boolean CheckShapesPair(const TopoDS_Shape& aShape1,
          gp_Dir aDir1 = aCurve1.Line().Direction();
          gp_Dir aDir2 = aCurve2.Line().Direction();
          if (!(aDir1.IsParallel(aDir2, Precision::Confusion()))) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
            cout << " Lines are not parallel"<<endl;
 #endif
            return Standard_False;
@@ -1448,14 +1498,14 @@ static Standard_Boolean CheckShapesPair(const TopoDS_Shape& aShape1,
          gp_Pnt aCntr1 = aCurve1.Circle().Location(); //get the circle center
          gp_Pnt aCntr2 = aCurve2.Circle().Location(); //get the circle center
          if (!aCntr1.IsEqual(aCntr2,Precision::Confusion())){
-#ifdef DEB
+#ifdef OCCT_DEBUG
            cout << " Circles are not concentric"<<endl;
 #endif
            return Standard_False;
          }
        }
       else {
-#ifdef DEB
+#ifdef OCCT_DEBUG
        cout << "Incorrect pair of curves "<<endl;
 #endif
        return Standard_False;
@@ -1477,7 +1527,7 @@ static Standard_Boolean CheckShapesPair(const TopoDS_Shape& aShape1,
        {
          gp_Pnt aCntr = aCurve.Circle().Location();
          if (!aCntr.IsEqual(aPnt, Precision::Confusion())){
-#ifdef DEB
+#ifdef OCCT_DEBUG
            cout << " The point doesn't coincide with the circle center"<<endl;
 #endif
            return Standard_False;
@@ -1496,7 +1546,7 @@ void TPrsStd_ConstraintTools::ComputeEqualRadius(const Handle(TDataXtd_Constrain
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 2) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeEqualRadius: at least two geometries are needed" << endl;;
 #endif
     NullifyAIS(anAIS);
@@ -1507,7 +1557,7 @@ void TPrsStd_ConstraintTools::ComputeEqualRadius(const Handle(TDataXtd_Constrain
   
   GetShapesAndGeom(aConst, shape1, shape2, ageom3);
   if (shape1.IsNull()||shape2.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeEqualRadius : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1551,7 +1601,7 @@ void TPrsStd_ConstraintTools::ComputeEqualRadius(const Handle(TDataXtd_Constrain
        aDir1.IsParallel(aDir2, Precision::Confusion()))
       aplane = aPlane2;
     else {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeRadiusRelation: nul plane" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -1588,7 +1638,7 @@ void TPrsStd_ConstraintTools::ComputeDiameter(const Handle(TDataXtd_Constraint)&
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 1) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeDiameter: at least one constrainte is needed" << endl;;
 #endif
     NullifyAIS(anAIS);
@@ -1598,7 +1648,7 @@ void TPrsStd_ConstraintTools::ComputeDiameter(const Handle(TDataXtd_Constraint)&
   
   GetOneShape(aConst,shape1);
   if (shape1.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeDiameter : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1628,7 +1678,7 @@ void TPrsStd_ConstraintTools::ComputeDiameter(const Handle(TDataXtd_Constraint)&
     GetGeom(aConst,ageom2);
     Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
     if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeDiameter: nul plane" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -1649,14 +1699,14 @@ void TPrsStd_ConstraintTools::ComputeFix(const Handle(TDataXtd_Constraint)& aCon
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 1) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeFix: at least one constrainte is needed" << endl;;
 #endif
     NullifyAIS(anAIS);
     return;
   }
   if (!aConst->IsPlanar()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeFix: must be a planar constraint" << endl;;
 #endif
     NullifyAIS(anAIS);
@@ -1668,7 +1718,7 @@ void TPrsStd_ConstraintTools::ComputeFix(const Handle(TDataXtd_Constraint)& aCon
   
   GetOneShape(aConst,shape1);
   if (shape1.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeFix : null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1678,7 +1728,7 @@ void TPrsStd_ConstraintTools::ComputeFix(const Handle(TDataXtd_Constraint)& aCon
   GetGeom(aConst,ageom2);
   Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
   if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeFix: nul plane" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1712,9 +1762,11 @@ void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)&
   Standard_Boolean is_planar (aConst->IsPlanar());
   Handle(Geom_Plane) aplane;      
   if (is_planar) {
-    GetGeom (aConst,aplane);
+    Handle(Geom_Geometry) ageom;
+    GetGeom (aConst,ageom);
+    aplane = Handle(Geom_Plane)::DownCast (ageom);
     if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
       cout << "TPrsStd_ConstraintTools::ComputeOffset: null plane" << endl;
 #endif
       NullifyAIS(anAIS);
@@ -1741,7 +1793,7 @@ void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)&
   }
 
   if (S1.IsNull() || S2.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeOffset: null shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -1752,7 +1804,7 @@ void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)&
   Standard_Real val1;
   TCollection_ExtendedString txt;
   Handle(AIS_LengthDimension) ais;
-  //Handle(AIS_Drawer) aDrawer;
+  //Handle(Prs3d_Drawer) aDrawer;
 
   if (nbgeom == 1)
   {
@@ -1775,8 +1827,11 @@ void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)&
       }
 
       if (is_planar)
+      {
         ais->SetCustomPlane (aplane->Pln());
-        anAIS = ais;
+      }
+
+      anAIS = ais;
       return;
     }
     else
@@ -1786,20 +1841,12 @@ void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)&
       BRepAdaptor_Curve CURVE(OE);
       if (CURVE.GetType() == GeomAbs_Line)  {
        // Works only with line !!
-//#ifndef DEB
-        Handle_Geom_Geometry aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
-        gp_Lin OLin = ((Handle(Geom_Line)&) aGeomGeometry)->Lin();
-//#else
-//     gp_Lin OLin = ((Handle(Geom_Line)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Lin();
-//#endif
+        Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
+        gp_Lin OLin = Handle(Geom_Line)::DownCast (aGeomGeometry)->Lin();
        TopoDS_Edge NE = TopoDS::Edge(S2);
        CURVE.Initialize (NE);
-//#ifndef DEB
         aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
-        gp_Lin NLin = ((Handle(Geom_Line)&)aGeomGeometry)->Lin();
-//#else
-//     gp_Lin NLin = ((Handle(Geom_Line)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Lin();
-//#endif
+        gp_Lin NLin = Handle(Geom_Line)::DownCast (aGeomGeometry)->Lin();
        gp_Dir TDir (NLin.Location().XYZ() - OLin.Location().XYZ());
        aplane = new Geom_Plane (NLin.Location(),NLin.Direction()^TDir);
 
@@ -1817,12 +1864,8 @@ void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)&
       }
       else
       if (CURVE.GetType() == GeomAbs_Circle)  {
-//#ifndef DEB
-        Handle_Geom_Geometry aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
-        gp_Ax1 ax = ((Handle(Geom_Circle)&) aGeomGeometry)->Circ().Axis();
-//#else
-//     gp_Ax1 ax = ((Handle(Geom_Circle)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Circ().Axis();
-//#endif
+        Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
+        gp_Ax1 ax = Handle(Geom_Circle)::DownCast (aGeomGeometry)->Circ().Axis();
        aplane = new Geom_Plane (ax.Location(),ax.Direction());
        is_planar = Standard_True;
       }
@@ -1843,12 +1886,8 @@ void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)&
 
       BRepBuilderAPI_MakeFace MkF (w1,Standard_True);
       if (MkF.IsDone())  {
-//#ifndef DEB
-        Handle_Geom_Surface aGeomSurface = BRep_Tool::Surface(MkF.Face());
-        aplane = (Handle(Geom_Plane)&) aGeomSurface ;
-//#else
-//     aplane = ((Handle(Geom_Plane)&) BRep_Tool::Surface(MkF.Face()));
-//#endif
+        Handle(Geom_Surface) aGeomSurface = BRep_Tool::Surface(MkF.Face());
+        aplane = Handle(Geom_Plane)::DownCast (aGeomSurface);
        is_planar = Standard_True;
       }
     }
@@ -1886,7 +1925,7 @@ void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)&
     return;
   }
 
-#ifdef DEB
+#ifdef OCCT_DEBUG
   cout << "TPrsStd_ConstraintTools::ComputeOffset: Case not implemented" << endl;
 #endif
   NullifyAIS(anAIS);
@@ -1903,13 +1942,12 @@ void TPrsStd_ConstraintTools::ComputePlacement
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 2) 
-    Standard_ProgramError::Raise
-      ("TPrsStd_ConstraintTools::ComputePlacement: at leat two constraints are needed");
+    throw Standard_ProgramError("TPrsStd_ConstraintTools::ComputePlacement: at leat two constraints are needed");
   
   TopoDS_Shape shape1,shape2 ;
   GetTwoShapes(aConst,shape1,shape2);
   if (shape1.IsNull() || shape2.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -2040,7 +2078,7 @@ void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 2) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeCoincident: at leat two constraintes are needed" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -2048,7 +2086,7 @@ void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint
   }
   
   if (!aConst->IsPlanar()) { 
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeCoincident: must be a planar constraint" << endl;
 #endif
     anAIS.Nullify() ; 
@@ -2056,10 +2094,11 @@ void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint
   }
   
   TopoDS_Shape shape1,shape2 ;
-  Handle(Geom_Plane) aplane;
-  GetShapesAndGeom(aConst,shape1,shape2,aplane);
+  Handle(Geom_Geometry) ageom;
+  GetShapesAndGeom(aConst,shape1,shape2,ageom);
+  Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast (ageom);
   if (shape1.IsNull() || shape2.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -2069,7 +2108,7 @@ void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint
   GetGoodShape(shape1);
   GetGoodShape(shape2);
   if (aplane.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul plane" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -2102,7 +2141,7 @@ void TPrsStd_ConstraintTools::ComputeRound(const Handle(TDataXtd_Constraint)& aC
 {
   Standard_Integer nbgeom = aConst->NbGeometries();
   if (nbgeom < 1) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputeRound: at leat one geometry is needed" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -2111,7 +2150,7 @@ void TPrsStd_ConstraintTools::ComputeRound(const Handle(TDataXtd_Constraint)& aC
   TopoDS_Shape shape1;
   GetOneShape (aConst,shape1);
   if (shape1.IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl;
 #endif
     NullifyAIS(anAIS);
@@ -2156,7 +2195,7 @@ void TPrsStd_ConstraintTools::GetGeom(const Handle(TDataXtd_Constraint)& aConst,
 {  
   Handle(TNaming_NamedShape) atgeom = aConst->GetPlane();
   if (atgeom.IsNull()) {
-#ifdef DEB    
+#ifdef OCCT_DEBUG
     cout<<"TPrsStd_ConstraintTools::GetGeom : aConst->GetPlane().IsNull()"<<endl;
 #endif
     return;
@@ -2176,7 +2215,7 @@ void TPrsStd_ConstraintTools::GetGeom(const Handle(TDataXtd_Constraint)& aConst,
   if (TDataXtd_Geometry::Plane(label,aplane)) aGeom =  new Geom_Plane(aplane);
   else if (TDataXtd_Geometry::Line(label,anaxis)) aGeom =  new Geom_Line(anaxis);
   else if (TDataXtd_Geometry::Point(label,apoint)) aGeom =  new Geom_CartesianPoint(apoint);
-#ifdef DEB
+#ifdef OCCT_DEBUG
   else {
     cout << "TPrsStd_ConstraintTools::GetGeom no geom on label " << endl;
   }