]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
Salome HOME
Sources formated according to the codeing standards
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintDistance.cpp
index ab8bba03646e1e80c09640c3a7bbd73c8d6b4390..e8ea4bfbed0c10497c1a1b40e82b36023e3b74cf 100644 (file)
@@ -23,7 +23,7 @@ SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
 //*************************************************************************************
 void SketchPlugin_ConstraintDistance::initAttributes()
 {
-  data()->addAttribute(SketchPlugin_Constraint::VALUE(),    ModelAPI_AttributeDouble::type());
+  data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::type());
   data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
@@ -33,28 +33,27 @@ void SketchPlugin_ConstraintDistance::initAttributes()
 void SketchPlugin_ConstraintDistance::execute()
 {
   boost::shared_ptr<ModelAPI_Data> aData = data();
-  AttributeDoublePtr anAttr_Value =
-    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+  AttributeDoublePtr anAttr_Value = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
       aData->attribute(SketchPlugin_Constraint::VALUE()));
 
   if (!anAttr_Value->isInitialized()) {
-    boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = 
-      getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
-    boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = 
-      getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
-  
-    if (aPoint_A && aPoint_B) { // both points
-        anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt()));
+    boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(
+        aData, SketchPlugin_Constraint::ENTITY_A());
+    boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(
+        aData, SketchPlugin_Constraint::ENTITY_B());
+
+    if (aPoint_A && aPoint_B) {  // both points
+      anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt()));
     } else {
-      if (!aPoint_A && aPoint_B) { //Line and point
-        boost::shared_ptr<SketchPlugin_Line> aLine = 
-          getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
+      if (!aPoint_A && aPoint_B) {  //Line and point
+        boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
+            aData, SketchPlugin_Constraint::ENTITY_A());
         if (aLine)
           anAttr_Value->setValue(aLine->distanceToPoint(aPoint_B->pnt()));
-      } else if (aPoint_A && !aPoint_B) { // Point and line
-        boost::shared_ptr<SketchPlugin_Line> aLine = 
-          getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
-        if(aLine)
+      } else if (aPoint_A && !aPoint_B) {  // Point and line
+        boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
+            aData, SketchPlugin_Constraint::ENTITY_B());
+        if (aLine)
           anAttr_Value->setValue(aLine->distanceToPoint(aPoint_A->pnt()));
       }
     }
@@ -70,8 +69,10 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi
   boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
 
   DataPtr aData = data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(
+      aData, SketchPlugin_Constraint::ENTITY_A());
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(
+      aData, SketchPlugin_Constraint::ENTITY_B());
 
   boost::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
   boost::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
@@ -80,15 +81,15 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi
     aPnt_A = aPoint_A->pnt();
     aPnt_B = aPoint_B->pnt();
   } else if (!aPoint_A && aPoint_B) {
-    boost::shared_ptr<SketchPlugin_Line> aLine = 
-      getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
+    boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
+        aData, SketchPlugin_Constraint::ENTITY_A());
     if (aLine) {
       aPnt_B = aPoint_B->pnt();
       aPnt_A = getProjectionPoint(aLine, aPnt_B);
     }
   } else if (aPoint_A && !aPoint_B) {
-    boost::shared_ptr<SketchPlugin_Line> aLine = 
-      getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
+    boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
+        aData, SketchPlugin_Constraint::ENTITY_B());
     if (aLine) {
       aPnt_A = aPoint_A->pnt();
       aPnt_B = getProjectionPoint(aLine, aPnt_A);
@@ -97,18 +98,18 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi
   if (!aPnt_A || !aPnt_B)
     return thePrevious;
 
-  boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+  boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = boost::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
 
   boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPnt_A->x(), aPnt_A->y());
   boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPnt_B->x(), aPnt_B->y());
-  boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = aFlyOutAttr->isInitialized() ? 
-                                              sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()) : 
-                                              boost::shared_ptr<GeomAPI_Pnt>();
+  boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt =
+      aFlyOutAttr->isInitialized() ?
+          sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()) : boost::shared_ptr<GeomAPI_Pnt>();
 
   // value calculation
-  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
-    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
+  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
   double aValue = aValueAttr->value();
 
   AISObjectPtr anAIS = thePrevious;
@@ -117,7 +118,8 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi
   anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue);
 
   // Set color from preferences
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "distance_color", DISTANCE_COLOR);
+  std::vector<int> aRGB = Config_PropManager::color("Visualization", "distance_color",
+                                                    DISTANCE_COLOR);
   anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
   return anAIS;
 }
@@ -129,8 +131,8 @@ void SketchPlugin_ConstraintDistance::move(double theDeltaX, double theDeltaY)
   if (!aData->isValid())
     return;
 
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
   aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
 }
 
@@ -144,32 +146,33 @@ boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
     return aPointAttr;
 
   FeaturePtr aFeature;
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
   if (anAttr)
     aFeature = ModelAPI_Feature::feature(anAttr->object());
 
   if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
-    aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                           (aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+    aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+        aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
   else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID())
-    aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                          (aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
+    aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+        aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
   else if (anAttr->attr()) {
-      aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+    aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
   }
   return aPointAttr;
 }
 
 //*************************************************************************************
-boost::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData, const std::string& theAttribute)
+boost::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData,
+                                                    const std::string& theAttribute)
 {
   boost::shared_ptr<SketchPlugin_Line> aLine;
   if (!theData)
     return aLine;
 
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
   if (anAttr) {
     FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
     if (aFeature && aFeature->getKind() == SketchPlugin_Line::ID()) {
@@ -180,16 +183,15 @@ boost::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData, const std::
 }
 
 //*************************************************************************************
-boost::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(const boost::shared_ptr<SketchPlugin_Line>& theLine, 
-                                                          const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+boost::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
+    const boost::shared_ptr<SketchPlugin_Line>& theLine,
+    const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
 {
   boost::shared_ptr<ModelAPI_Data> aData = theLine->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aData->attribute(SketchPlugin_Line::START_ID()));
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aData->attribute(SketchPlugin_Line::END_ID()));
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aData->attribute(SketchPlugin_Line::START_ID()));
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aData->attribute(SketchPlugin_Line::END_ID()));
 
   GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y());
   return aLin2d.project(thePoint);