]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Sep 2014 07:37:24 +0000 (11:37 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Sep 2014 07:37:24 +0000 (11:37 +0400)
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp
src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 7f068f0f9cd15267c9f23be3e9026b86c3b1b22b..22863757e8a855bdd25058438d88c99c827d74f4 100644 (file)
@@ -23,6 +23,8 @@
 #include <AIS_RadiusDimension.hxx>
 #include <AIS_Shape.hxx>
 
+const double tolerance = 1e-7;
+
 const int CONSTRAINT_TEXT_HEIGHT = 28;  /// the text height of the constraint
 const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20;  /// the text selection tolerance
 
@@ -67,9 +69,14 @@ void GeomAPI_AISObject::createDistance(boost::shared_ptr<GeomAPI_Pnt> theStartPo
 {
   double aFlyout = 0;
   if (theFlyoutPoint) {
-    boost::shared_ptr<GeomAPI_Lin> aLine = boost::shared_ptr<GeomAPI_Lin>(
-        new GeomAPI_Lin(theStartPoint, theEndPoint));
-    double aDist = aLine->distance(theFlyoutPoint);
+    double aDist = 0.0;
+    if (theStartPoint->distance(theEndPoint) < tolerance)
+      aDist = theStartPoint->distance(theFlyoutPoint);
+    else {
+      boost::shared_ptr<GeomAPI_Lin> aLine = boost::shared_ptr<GeomAPI_Lin>(
+          new GeomAPI_Lin(theStartPoint, theEndPoint));
+      aDist = aLine->distance(theFlyoutPoint);
+    }
 
     boost::shared_ptr<GeomAPI_XYZ> aLineDir = theEndPoint->xyz()->decreased(theStartPoint->xyz());
     boost::shared_ptr<GeomAPI_XYZ> aFOutDir = theFlyoutPoint->xyz()->decreased(
index b7e4753079617b402eb64d7b99418b5e34968f43..a236fc8bb00135cd62e014ec1236d88b2e83b9c2 100644 (file)
@@ -10,6 +10,7 @@
 #include <Geom_Plane.hxx>
 #include <Geom_Surface.hxx>
 #include <TopExp_Explorer.hxx>
+#include <BRep_Builder.hxx>
 
 #include <Precision.hxx>
 const double tolerance = Precision::Angular();
@@ -38,6 +39,9 @@ boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
 
   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
   TopExp_Explorer aFaceExp(aShape, TopAbs_FACE);
+  TopoDS_Compound aFaces; // use only faces from the shape: make compound for this
+  BRep_Builder aBuilder;
+  aBuilder.MakeCompound(aFaces);
   for (; aFaceExp.More(); aFaceExp.Next()) {
     const TopoDS_Face& aFace = (const TopoDS_Face&) aFaceExp.Current();
     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aFace));
@@ -50,10 +54,15 @@ boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
       isFirstNorm = false;
     } else if (!aShapeNormal.IsEqual(aNormal, tolerance))  // non-planar shapes is not supported for extrusion yet
       return boost::shared_ptr<GeomAPI_Shape>();
+    aBuilder.Add(aFaces, aFace);
   }
+  if (aFaces.IsNull())
+    return boost::shared_ptr<GeomAPI_Shape>();
 
   boost::shared_ptr<GeomAPI_Dir> aDir(
       new GeomAPI_Dir(aShapeNormal.X(), aShapeNormal.Y(), aShapeNormal.Z()));
 
-  return GeomAlgoAPI_Extrusion::makeExtrusion(theShape, aDir, theSize);
+  boost::shared_ptr<GeomAPI_Shape> aFacesShape(new (GeomAPI_Shape));
+  aFacesShape->setImpl(new TopoDS_Shape(aFaces));
+  return GeomAlgoAPI_Extrusion::makeExtrusion(aFacesShape, aDir, theSize);
 }
index ed3bf8fec901edecef4e221c3a9f8b6c55a4a515..edff6f1a43832d9d90b3ac0832c0493eb6f13298 100644 (file)
@@ -196,7 +196,7 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
             aProcEdges.pop_back();
           } while (aCurVertex != aProcVertexes.back());
           aCurDir = aCN.Reversed();
-          aCurNorm = aNorm.Reversed();
+          //aCurNorm = aNorm.Reversed();
           continue;
         }
       }
@@ -229,27 +229,16 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
       std::list<TopoDS_Edge>::iterator aCopyELoop = anEdgeIter;
       removeWasteEdges(aVertIter, anEdgeIter, aProcVertexes.end(), aProcEdges.end(), aMapVE);
 
-      // revert the list of remaining edges
-      std::list<TopoDS_Vertex> aRemainVertexes;
-      for (; aVertIter != aProcVertexes.end(); aVertIter++)
-        aRemainVertexes.push_front(*aVertIter);
-      std::list<TopoDS_Edge> aRemainEdges;
-      for (; anEdgeIter != aProcEdges.end(); anEdgeIter++)
-        aRemainEdges.push_front(*anEdgeIter);
-      // remove edges and vertexes used in the loop and add remaining ones
-      aProcVertexes.erase(aCopyVLoop, aProcVertexes.end());
-      aProcVertexes.insert(aProcVertexes.end(), aRemainVertexes.begin(), aRemainVertexes.end());
-      aProcEdges.erase(aCopyELoop, aProcEdges.end());
-      aProcEdges.insert(aProcEdges.end(), aRemainEdges.begin(), aRemainEdges.end());
-
       // Recalculate current vertex and current direction
-      if (!aProcVertexes.empty()) {
-        aNextVertex = aProcVertexes.back();
-        if (!aProcEdges.empty())
-          aNextDir = getOuterEdgeDirection(aProcEdges.back(), aNextVertex);
-        else
-          aNextDir = aDirY;
+      aProcEdges.clear();
+      aProcVertexes.clear();
+      if (aMapVE.Extent() > 0)
+      {
+        aNextVertex = findStartVertex(aMapVE, aDirX, aDirY);
+        aProcVertexes.push_back(aNextVertex);
       }
+      aNextDir = aDirY.Reversed();
+      aCurNorm = aNorm.Reversed();
     }
 
     // if next vertex connected only to alone edge, this is a part of wire (not a closed loop),
@@ -344,7 +333,8 @@ void GeomAlgoAPI_SketchBuilder::fixIntersections(
       for (; aVert2.More(); aVert2.Next()) {
         const TopoDS_Vertex& aV = (const TopoDS_Vertex&)aVert2.Current();
         aClassifier.Perform(aF1, BRep_Tool::Pnt(aV), tolerance);
-        if (aClassifier.State() != TopAbs_IN && aClassifier.State() != TopAbs_ON)
+        TopAbs_State aState = aClassifier.State();
+        if (aState != TopAbs_IN && aState != TopAbs_ON)
           break;
       }
       if (aVert2.More()) {  // second shape is not inside first, change the shapes order and repeat comparision
@@ -354,29 +344,42 @@ void GeomAlgoAPI_SketchBuilder::fixIntersections(
         for (; aVert1.More(); aVert1.Next()) {
           const TopoDS_Vertex& aV = (const TopoDS_Vertex&)aVert2.Current();
           aClassifier.Perform(aF2, BRep_Tool::Pnt(aV), tolerance);
-          if (aClassifier.State() != TopAbs_IN && aClassifier.State() != TopAbs_ON)
+          TopAbs_State aState = aClassifier.State();
+          if (aState != TopAbs_IN && aState != TopAbs_ON)
             break;
         }
         if (!aVert1.More()) {  // first shape should be cut from the second
           BRepAlgoAPI_Cut aCut((*anIter2)->impl<TopoDS_Shape>(), (*anIter1)->impl<TopoDS_Shape>());
           aCut.Build();
           TopExp_Explorer anExp(aCut.Shape(), TopAbs_FACE);
-          (*anIter2)->setImpl(new TopoDS_Shape(anExp.Current()));
+          bool isFirstFace = true;
           for (anExp.Next(); anExp.More(); anExp.Next()) {
-            boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
-            aShape->setImpl(new TopoDS_Shape(anExp.Current()));
-            theFaces.push_back(aShape);
+            if (anExp.Current().ShapeType() != TopAbs_FACE) continue;
+            if (isFirstFace) {
+              (*anIter2)->setImpl(new TopoDS_Shape(anExp.Current()));
+              isFirstFace = false;
+            } else {
+              boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
+              aShape->setImpl(new TopoDS_Shape(anExp.Current()));
+              theFaces.push_back(aShape);
+            }
           }
         }
       } else {  // second shape should be cut from the first
         BRepAlgoAPI_Cut aCut((*anIter1)->impl<TopoDS_Shape>(), (*anIter2)->impl<TopoDS_Shape>());
         aCut.Build();
         TopExp_Explorer anExp(aCut.Shape(), TopAbs_FACE);
-        (*anIter1)->setImpl(new TopoDS_Shape(anExp.Current()));
+        bool isFirstFace = true;
         for (anExp.Next(); anExp.More(); anExp.Next()) {
-          boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
-          aShape->setImpl(new TopoDS_Shape(anExp.Current()));
-          theFaces.push_back(aShape);
+          if (anExp.Current().ShapeType() != TopAbs_FACE) continue;
+          if (isFirstFace) {
+            (*anIter1)->setImpl(new TopoDS_Shape(anExp.Current()));
+            isFirstFace = false;
+          } else {
+            boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
+            aShape->setImpl(new TopoDS_Shape(anExp.Current()));
+            theFaces.push_back(aShape);
+          }
         }
       }
     }
index 2f286672d00acfa7f7124292b82b6c66c26eeb8e..9e21d483181271c7392633267faedee67cd52ab0 100644 (file)
@@ -559,6 +559,13 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>&
   QApplication::restoreOverrideCursor();
 }
 
+bool XGUI_Workshop::isActiveOperationAborted()
+{
+  if(!myOperationMgr->hasOperation())
+    return true;
+  return myOperationMgr->abortOperation();
+}
+
 //******************************************************
 void XGUI_Workshop::onExit()
 {
@@ -602,7 +609,7 @@ void XGUI_Workshop::onNew()
 //******************************************************
 void XGUI_Workshop::onOpen()
 {
-  if(!myOperationMgr->abortOperation())
+  if(!isActiveOperationAborted())
     return;
   //save current file before close if modified
   SessionPtr aSession = ModelAPI_Session::get();
@@ -636,14 +643,13 @@ void XGUI_Workshop::onOpen()
   myObjectBrowser->rebuildDataTree();
   displayAllResults();
   updateCommandStatus();
-  myMainWindow->setCurrentDir(myCurrentDir);
   QApplication::restoreOverrideCursor();
 }
 
 //******************************************************
 bool XGUI_Workshop::onSave()
 {
-  if(!myOperationMgr->abortOperation())
+  if(!isActiveOperationAborted())
     return false;
   if (myCurrentDir.isEmpty()) {
     return onSaveAs();
@@ -658,7 +664,7 @@ bool XGUI_Workshop::onSave()
 //******************************************************
 bool XGUI_Workshop::onSaveAs()
 {
-  if(!myOperationMgr->abortOperation())
+  if(!isActiveOperationAborted())
     return false;
   QFileDialog dialog(mainWindow());
   dialog.setWindowTitle(tr("Select directory to save files..."));
index f9a5ee50dc7c19e7031dcd8746764a0959dbff9d..b969861682dec1ec56492aa3dbdf5e594737f444 100644 (file)
@@ -175,6 +175,14 @@ Q_OBJECT
   */
   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
 
+  /*
+   * If there is an active (uncommited) operation shows a prompt to abort it
+   * and performs abortion if user agreed. Returns true if
+   * - operation aborted successfully
+   * - there is no active operation
+   */
+  bool isActiveOperationAborted();
+
 signals:
   void salomeViewerSelection();
   void errorOccurred(const QString&);
@@ -202,9 +210,6 @@ signals:
 
   void activateLastPart();
 
-  /// Display all results of the current document
-  void displayAllResults();
-
  protected:
   //Event-loop processing methods:
   void addFeature(const Config_FeatureMessage*);
@@ -219,6 +224,7 @@ signals:
 
   QList<QAction*> getModuleCommands() const;
 
+  void displayAllResults();
   void displayDocumentResults(DocumentPtr theDoc);
   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);