Salome HOME
Initialize myDeflection (and other fields) to avoid FPE at setting deflection
[modules/geom.git] / src / OBJECT / GEOM_Actor.cxx
index b152bafd2b357d2d40dce3af3f218ac26e0ff1eb..eeb5f0dc31be7ac75588590a8ff1723a6896e46e 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 //  GEOM OBJECT : interactive object for Geometry entities visualization
@@ -39,6 +39,8 @@
 #include "GEOM_ShadingFace.h"
 #include "SVTK_Actor.h"
 
+#include <OCC2VTK_Tools.h>
+
 #include <vtkObjectFactory.h> 
 #include <vtkRenderer.h> 
 #include <vtkProperty.h> 
  
 #include <TopAbs_ShapeEnum.hxx>
 #include <TopExp_Explorer.hxx>
-#include <Poly_Triangulation.hxx>
-#include <BRepMesh_IncrementalMesh.hxx>
-#include <Bnd_Box.hxx>
 #include <TopoDS.hxx>
 #include <BRep_Tool.hxx>
-#include <BRepBndLib.hxx>
-#include <TopTools_ListOfShape.hxx>
-#include <TopoDS_Iterator.hxx>
 #include <TopExp.hxx>
  
 #include <vtkPolyDataWriter.h> 
 #endif
 
 GEOM_Actor::GEOM_Actor(): 
+  isOnlyVertex(false),
+
+  myDeflection(-1),
+  myIsForced(false),
+
   //  myDisplayMode(eWireframe), 
   myIsSelected(false), 
   myVectorMode(false),
+
   myVertexActor(GEOM_DeviceActor::New(),true), 
   myVertexSource(GEOM_VertexSource::New(),true), 
  
@@ -105,8 +107,7 @@ GEOM_Actor::GEOM_Actor():
 
   myHighlightProp(vtkProperty::New()),
   myPreHighlightProp(vtkProperty::New()),
-  myShadingFaceProp(vtkProperty::New()),
-  isOnlyVertex(false)
+  myShadingFaceProp(vtkProperty::New())
 { 
 #ifdef MYDEBUG
   MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
@@ -178,6 +179,7 @@ GEOM_Actor::GEOM_Actor():
 
   // Toggle display mode 
   setDisplayMode(0); // WIRE FRAME
+  SetVectorMode(0);  //
 
 } 
  
@@ -354,51 +356,23 @@ GEOM_Actor
   return myVectorMode;
 }
 
-static 
-void 
-MeshShape(const TopoDS_Shape& theShape,
-          float& theDeflection, 
-          bool theIsRelative)
-{ 
-  static Standard_Real RELATIVE_DEFLECTION = 0.0001; 
-  Standard_Real aDeflection = theDeflection; 
-
-  if(theDeflection <= 0) { // Compute default theDeflection
-    Bnd_Box B;
-    BRepBndLib::Add(theShape, B);
-    Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
-    B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
-    Standard_Real aDiagonal = (aXmax-aXmin)*(aXmax-aXmin) +
-                              (aYmax-aYmin)*(aYmax-aYmin) +
-                              (aZmax-aZmin)*(aZmax-aZmin);
-    aDiagonal = sqrt(aDiagonal); 
-    aDeflection = aDiagonal*RELATIVE_DEFLECTION; 
-    if(theIsRelative) 
-      theDeflection = RELATIVE_DEFLECTION; 
-    else 
-      theDeflection = aDeflection; 
-  }
-  
-  BRepMesh_IncrementalMesh aMesh(theShape,aDeflection);
-}
-
 void  
 GEOM_Actor:: 
-SetDeflection(float theDeflection, bool theIsRelative
+SetDeflection(float theDeflection) 
 { 
+  if( myDeflection == theDeflection ) 
+    return;
+    
   myDeflection = theDeflection; 
-  myIsRelative = theIsRelative; 
-  MeshShape(myShape,myDeflection,myIsRelative); 
  
+  GEOM::MeshShape(myShape,myDeflection);
+  
   SetModified(); 
-} 
+}
 
 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
                            float theDeflection,
-                           bool theIsRelative,
-                           bool theIsVector)
+                          bool theIsVector)
 {
   myShape = theShape;
 
@@ -415,13 +389,19 @@ void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
      myVertexSource->AddVertex(aVertex);
   }
-  SetDeflection(theDeflection, theIsRelative);
+  
+  SetDeflection(theDeflection);
 
   // look if edges are free or shared
   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
   
-  SetShape(theShape,anEdgeMap,theIsVector);
+  GEOM::SetShape(theShape,anEdgeMap,theIsVector,
+                 myIsolatedEdgeSource.Get(),
+                 myOneFaceEdgeSource.Get(),
+                 mySharedEdgeSource.Get(),
+                 myWireframeFaceSource.Get(),
+                 myShadingFaceSource.Get());
   isOnlyVertex =  
     myIsolatedEdgeSource->IsEmpty() &&
     myOneFaceEdgeSource->IsEmpty() &&
@@ -436,71 +416,12 @@ void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
   }
 }
 
-void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
-                           const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
-                           bool theIsVector)
-{
-  if (theShape.ShapeType() == TopAbs_COMPOUND) {
-    TopoDS_Iterator anItr(theShape);
-    for (; anItr.More(); anItr.Next()) {
-      SetShape(anItr.Value(),theEdgeMap,theIsVector);
-    }
-  }
-
-  switch (theShape.ShapeType()) {
-    case TopAbs_WIRE: {
-      TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE);
-      for (; anEdgeExp.More(); anEdgeExp.Next()){
-        const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
-        if (!BRep_Tool::Degenerated(anEdge))
-          myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
-      }
-      break;
-    }
-    case TopAbs_EDGE: {
-      const TopoDS_Edge& anEdge = TopoDS::Edge(theShape);
-      if (!BRep_Tool::Degenerated(anEdge))
-        myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
-      break;
-    }
-    case TopAbs_VERTEX: {
-      break;
-    }
-    default: {
-      TopExp_Explorer aFaceExp (theShape,TopAbs_FACE);
-      for(; aFaceExp.More(); aFaceExp.Next()) {
-        const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current());
-        myWireframeFaceSource->AddFace(aFace);
-        myShadingFaceSource->AddFace(aFace);
-        TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE);
-        for(; anEdgeExp.More(); anEdgeExp.Next()) {
-          const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
-          if(!BRep_Tool::Degenerated(anEdge)){
-            // compute the number of faces
-            int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent();
-            switch(aNbOfFaces){
-            case 0:  // isolated edge
-              myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
-              break;
-            case 1:  // edge in only one face
-              myOneFaceEdgeSource->AddEdge(anEdge,theIsVector);
-              break;
-            default: // edge shared by at least two faces
-              mySharedEdgeSource->AddEdge(anEdge,theIsVector);
-            }
-          }
-        }
-      }
-    }
-  }
-}
-
 // OLD METHODS
 void GEOM_Actor::setDeflection(double adef) {
 #ifdef MYDEBUG
   MESSAGE ( "GEOM_Actor::setDeflection" );
 #endif
-  SetDeflection((float)adef,GetIsRelative());
+  SetDeflection((float)adef);
 }
 
 
@@ -625,7 +546,7 @@ void GEOM_Actor::ShallowCopy(vtkProp *prop)
   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
   if ( f != NULL )
     {
-      this->SetShape(f->getTopo(),f->GetDeflection(),f->GetIsRelative());
+      this->SetShape(f->getTopo(),f->GetDeflection());
     }
 
   // Now do superclass
@@ -770,9 +691,9 @@ GEOM_Actor
     switch(aSelectionMode){
     case ActorSelection : 
     {
-      //      cout << "=============== " << myIO->getEntry() << endl;
-      int nbio = mySelector->IObjectCount();
-      //      cout << " nbio = " << nbio << endl;
+//       cout << "=============== " << myIO->getEntry() << endl;
+//       int nbio = mySelector->IObjectCount();
+//       cout << " nbio = " << nbio << endl;
 
       if( !mySelector->IsSelected( myIO ) ) {
         //      printf ("!!!!!!!!!!!!!!!!\n");
@@ -899,3 +820,5 @@ void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
   matrix->Delete();
   this->Transform->Pop();  
 }  
+
+