Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 30 Dec 2014 09:51:28 +0000 (12:51 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 30 Dec 2014 09:51:28 +0000 (12:51 +0300)
1  2 
src/PartSet/PartSet_Tools.cpp

index dbecad94d3081513bcc2beeff6d4058356627444,3eb4cc1fb6f2b4f24a879494ad909d804ec2ead5..0b07da7e75db47c670207a7138059a3b9048c0fe
@@@ -308,35 -308,6 +308,35 @@@ void PartSet_Tools::createConstraint(Co
      aFeature->execute();
  }
  
 +std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
 +  findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
 +  double theTolerance, const QList<FeaturePtr>& theIgnore)
 +{
 +  std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
 +      new GeomAPI_Pnt2d(theX, theY));
 +
 +  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
 +  for (int i = 0; i < theSketch->numberOfSubs(); i++) {
 +    FeaturePtr aFeature = theSketch->subFeature(i);
 +    if (!theIgnore.contains(aFeature)) {
 +      anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
 +
 +      std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt;
 +      for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) {
 +        std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
 +          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
 +        double x = aCurPoint->x();
 +        double y = aCurPoint->y();
 +        if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) {
 +          return aCurPoint;
 +        }
 +      }
 +    }
 +  }
 +  return std::shared_ptr<GeomDataAPI_Point2D>();
 +}
 +
 +
  void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
                                     const std::string& theAttribute, double theClickedX,
                                     double theClickedY)
          aLast = anAttiributes.end();
      std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
      for (; anIt != aLast && !aFPoint; anIt++) {
 -      std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = std::dynamic_pointer_cast<
 -          GeomDataAPI_Point2D>(*anIt);
 -      if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())
 +      std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
 +        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
 +      if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())) {
          aFPoint = aCurPoint;
 +        break;
 +      }
      }
      if (aFPoint)
        PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint);
@@@ -384,23 -353,25 +384,25 @@@ std::shared_ptr<GeomAPI_Pln> PartSet_To
    std::shared_ptr<GeomAPI_Pln> aPlane;
  
    std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
-   std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-   std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-       aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-   if (aNormal && anOrigin) {
-     double adX = aNormal->x();
-     double adY = aNormal->y();
-     double adZ = aNormal->z();
-     if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
-       double aX = anOrigin->x();
-       double aY = anOrigin->y();
-       double aZ = anOrigin->z();
-       gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
-       double aA, aB, aC, aD;
-       aPln.Coefficients(aA, aB, aC, aD);
-       aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+   if (aData) {
+     std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+         aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+     std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+     if (aNormal && anOrigin) {
+       double adX = aNormal->x();
+       double adY = aNormal->y();
+       double adZ = aNormal->z();
+       if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
+         double aX = anOrigin->x();
+         double aY = anOrigin->y();
+         double aZ = anOrigin->z();
+         gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
+         double aA, aB, aC, aD;
+         aPln.Coefficients(aA, aB, aC, aD);
+         aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+       }
      }
    }
    return aPlane;