]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into SketchSolver SketchSolver
authorazv <azv@opencascade.com>
Tue, 24 Jun 2014 12:29:11 +0000 (16:29 +0400)
committerazv <azv@opencascade.com>
Tue, 24 Jun 2014 12:29:11 +0000 (16:29 +0400)
1  2 
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp

index b6ddb808aa950a4fa3b3a4d95fff1f15d2aad57f,d6e2b0075c7958cdbff8f71c55da53209fbd6f6f..599cb72e954d034d58537f0eb8dabf97ea51b4b2
@@@ -36,102 -24,29 +36,120 @@@ void SketchPlugin_ConstraintDistance::i
  
  void SketchPlugin_ConstraintDistance::execute()
  {
+   boost::shared_ptr<ModelAPI_Data> aData = data();
+   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_A = 
+           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_B = 
+           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+   AttributeDoublePtr anAttribute =
+       boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+   if (anAttr_A && anAttr_B && anAttribute->value() == 0)
+   {
+     FeaturePtr aFeature_A = anAttr_A->feature();
+     FeaturePtr aFeature_B = anAttr_B->feature();
+     double aValue = 40; // TODO
+     anAttribute->setValue(aValue);
+   }
  }
  
 -const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintDistance::preview()
 +Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape(
 +  Handle_AIS_InteractiveObject thePrevious)
  {
 -  /// \todo Preview for distance constraint
 -  return getPreview();
 +  if (!sketch())
 +    return thePrevious;
 +
 +  boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
 +
 +  DataPtr aData = data();
 +  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_A);
 +  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_B);
 +  if (!aPoint_A || !aPoint_B)
 +    return thePrevious;
 +
 +  // fly out calculation
 +  boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = 
 +    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
 +  boost::shared_ptr<GeomAPI_Pnt2d> aFlyOutPnt = aFlyOutAttr->pnt();
 +
 +  boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = 
 +    boost::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(),
 +                                                       aPoint_B->x(), aPoint_B->y()));
 +  boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aFlyOutPnt);
 +  double aDistance = aFlyOutPnt->distance(aResult);
 +
 +  if (!aFeatureLin->isRight(aFlyOutPnt))
 +    aDistance = -aDistance;
 +  double aFlyout = aDistance;
 +
 +  //Build dimension here
 +  boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y());
 +  boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y());
 +  if (aFlyout < 0)
 +    aPoint1.swap(aPoint2);
 +
 +  // value calculation
 +  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
 +    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
 +  double aValue = aValueAttr->value();
 +  if (aValue == 0) { // TODO! the default value
 +    aValue = aPoint1->distance(aPoint2);
 +  }
 +
 +  Handle(AIS_InteractiveObject) anAIS = thePrevious;
 +  if (anAIS.IsNull())
 +  {
 +    Handle(AIS_LengthDimension) aDimAIS = 
 +      new AIS_LengthDimension(aPoint1->impl<gp_Pnt>(), aPoint2->impl<gp_Pnt>(), aPlane->impl<gp_Pln>());
 +    aDimAIS->SetCustomValue(aValue);
 +
 +    Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
 +    anAspect->MakeArrows3d (Standard_False);
 +    anAspect->MakeText3d(false);
 +    anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
 +    anAspect->MakeTextShaded(false);
 +    aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
 +    aDimAIS->SetDimensionAspect (anAspect);
 +    aDimAIS->SetFlyout(aFlyout);
 +    aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
 +
 +    anAIS = aDimAIS;
 +  }
 +  else {
 +    // update presentation
 +    Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
 +    if (!aDimAIS.IsNull()) {
 +      aDimAIS->SetMeasuredGeometry(aPoint1->impl<gp_Pnt>(), aPoint2->impl<gp_Pnt>(), aPlane->impl<gp_Pln>());
 +      aDimAIS->SetCustomValue(aValue);
 +      aDimAIS->SetFlyout(aFlyout);
 +
 +      aDimAIS->Redisplay(Standard_True);
 +    }
 +  }
 +  return anAIS;
 +}
 +
 +
 +boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
 +                                                       const std::string& theAttribute)
 +{
 +  boost::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
 +
 +  if (!theData)
 +    return aPointAttr;
 +
 +  FeaturePtr aFeature;
 +  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
 +    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
 +  if (anAttr)
 +    aFeature = anAttr->feature();
 +
 +  if (aFeature && aFeature->getKind() == SKETCH_POINT_KIND)
 +    aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
 +                                           (aFeature->data()->attribute(POINT_ATTR_COORD));
 +  return aPointAttr;
  }