Salome HOME
Merge remote-tracking branch 'remotes/origin/EDF_2020_Lot2'
[modules/shaper.git] / src / PartSet / PartSet_Tools.cpp
index 09f2e143726776d661a379a62fd906eacffb590c..169ea993dd0f519ebb6e2172b9cb0134765eccc1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -115,15 +115,14 @@ gp_Pnt PartSet_Tools::convertClickToPoint(QPoint thePoint, Handle(V3d_View) theV
   if (theView.IsNull())
     return gp_Pnt();
 
-  V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
-  theView->Eye(XEye, YEye, ZEye);
-
+  V3d_Coordinate XAt, YAt, ZAt;
   theView->At(XAt, YAt, ZAt);
-  gp_Pnt EyePoint(XEye, YEye, ZEye);
   gp_Pnt AtPoint(XAt, YAt, ZAt);
 
-  gp_Vec EyeVector(EyePoint, AtPoint);
-  gp_Dir EyeDir(EyeVector);
+  double aX, aY, aZ;
+  theView->Proj(aX, aY, aZ);
+  gp_Dir EyeDir(aX, aY, aZ);
+  EyeDir.Reverse();
 
   gp_Pln PlaneOfTheView = gp_Pln(AtPoint, EyeDir);
   Standard_Real X, Y, Z;
@@ -131,9 +130,8 @@ gp_Pnt PartSet_Tools::convertClickToPoint(QPoint thePoint, Handle(V3d_View) theV
   gp_Pnt ConvertedPoint(X, Y, Z);
 
   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
-  gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(),
+  return ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(),
                                      PlaneOfTheView);
-  return ResultPoint;
 }
 
 void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
@@ -166,18 +164,20 @@ Handle(V3d_View) theView,
     gp_Pnt EyePoint(XEye, YEye, ZEye);
     gp_Pnt AtPoint(XAt, YAt, ZAt);
 
-    gp_Vec anEyeVec(EyePoint, AtPoint);
-    anEyeVec.Normalize();
+    if (EyePoint.Distance(AtPoint) > gp::Resolution()) {
+      gp_Vec anEyeVec(EyePoint, AtPoint);
+      anEyeVec.Normalize();
 
-    std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-        aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-    gp_Vec aNormalVec(aNormal->x(), aNormal->y(), aNormal->z());
+      std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+      gp_Vec aNormalVec(aNormal->x(), aNormal->y(), aNormal->z());
 
-    double aDen = anEyeVec * aNormalVec;
-    double aLVec = aDen != 0 ? aVec * aNormalVec / aDen : DBL_MAX;
+      double aDen = anEyeVec * aNormalVec;
+      double aLVec = aDen != 0 ? aVec * aNormalVec / aDen : DBL_MAX;
 
-    gp_Vec aDeltaVec = anEyeVec * aLVec;
-    aVec = aVec - aDeltaVec;
+      gp_Vec aDeltaVec = anEyeVec * aLVec;
+      aVec = aVec - aDeltaVec;
+    }
   }
   theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
   theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
@@ -384,10 +384,13 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(
   anIntoResult->setValue(SKETCH_PROJECTION_INCLUDE_INTO_RESULT);
   aProjectionFeature->execute();
 
+  ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+  bool isValid = aValidators->validate(aProjectionFeature);
+
   // if projection feature has not been created, exit
   AttributeRefAttrPtr aRefAttr = aProjectionFeature->data()->refattr(
     SketchPlugin_Projection::PROJECTED_FEATURE_ID());
-  if (!aRefAttr || !aRefAttr->isInitialized())
+  if (!isValid || !aRefAttr || !aRefAttr->isInitialized())
   {
     // remove external feature if the attribute is not filled
     std::set<FeaturePtr> aFeatures;
@@ -562,9 +565,9 @@ FeaturePtr PartSet_Tools::findFirstCoincidence(const FeaturePtr& theFeature,
   /// Find by result
   if (!aCoincident.get()) {
     std::list<ResultPtr> aResults = theFeature->results();
-    std::list<ResultPtr>::const_iterator aIt;
-    for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
-      ResultPtr aResult = *aIt;
+    std::list<ResultPtr>::const_iterator aResIt;
+    for (aResIt = aResults.cbegin(); aResIt != aResults.cend(); ++aResIt) {
+      ResultPtr aResult = *aResIt;
       aCoincident = findFirstCoincidenceByData(aResult->data(), thePoint);
       if (aCoincident.get())
         break;
@@ -598,8 +601,8 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>&
         FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
         if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
           if (!theCoincidencies.contains(aConstrFeature)) {
-            std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincedencePoint(aConstrFeature);
-            if (aPnt.get() && aOrig->isEqual(aPnt)) {
+            std::shared_ptr<GeomAPI_Pnt2d> aCoincPnt = getCoincedencePoint(aConstrFeature);
+            if (aCoincPnt.get() && aOrig->isEqual(aCoincPnt)) {
               findCoincidences(aConstrFeature, theList, theCoincidencies,
                 SketchPlugin_ConstraintCoincidence::ENTITY_A(), theIsAttributes);
               findCoincidences(aConstrFeature, theList, theCoincidencies,
@@ -613,9 +616,9 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>&
     // Find by Results
     ResultConstructionPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
     if (aResult.get()) {
-      FeaturePtr aFeature = ModelAPI_Feature::feature(aPnt->object());
-      if (!theList.contains(aFeature))
-        theList.append(aFeature);
+      FeaturePtr aFeat = ModelAPI_Feature::feature(aPnt->object());
+      if (!theList.contains(aFeat))
+        theList.append(aFeat);
       theCoincidencies.append(theStartCoin);
       theIsAttributes.append(false); // point attribute on a feature
 
@@ -626,8 +629,8 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>&
         FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
         if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
           if (!theCoincidencies.contains(aConstrFeature)) {
-            std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincedencePoint(aConstrFeature);
-            if (aPnt.get() && aOrig->isEqual(aPnt)) {
+            std::shared_ptr<GeomAPI_Pnt2d> aCoincPnt = getCoincedencePoint(aConstrFeature);
+            if (aCoincPnt.get() && aOrig->isEqual(aCoincPnt)) {
               findCoincidences(aConstrFeature, theList, theCoincidencies,
                 SketchPlugin_ConstraintCoincidence::ENTITY_A(), theIsAttributes);
               findCoincidences(aConstrFeature, theList, theCoincidencies,
@@ -733,7 +736,6 @@ void PartSet_Tools::sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite
   if (!theComposite.get())
     return;
 
-  static Events_Loop* aLoop = Events_Loop::loop();
   int aNumberOfSubs = theComposite->numberOfSubs();
   for (int i = 0; i < aNumberOfSubs; i++) {
     FeaturePtr aSubFeature = theComposite->subFeature(i);