From: vsv Date: Mon, 19 Oct 2015 16:37:59 +0000 (+0300) Subject: Documentation of the sources X-Git-Tag: V_2.0.0_alfa1~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=79c2d06fc1aa7bfee1bd1ff23db8031aa9edaa6a;p=modules%2Fshaper.git Documentation of the sources --- diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index 8b533fdba..f9e2e2959 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -43,6 +43,7 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { + // Get point of the presentation std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_A()); if (aPnt.get() == NULL) @@ -57,6 +58,9 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& if (aPtA.IsNull()) { aPtA = new Graphic3d_AspectMarker3d (); } + // Create the presentation as a combination of standard point markers + + // The external yellow contour aPtA->SetType(Aspect_TOM_RING3); aPtA->SetScale(2.); aPtA->SetColor(Quantity_NOC_YELLOW); @@ -67,12 +71,14 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& aPntArray->AddVertex (aPoint->x(), aPoint->y(), aPoint->z()); aGroup->AddPrimitiveArray (aPntArray); + // Make a black mid ring aPtA->SetType(Aspect_TOM_RING1); aPtA->SetScale(1.); aPtA->SetColor(Quantity_NOC_BLACK); aGroup->SetPrimitivesAspect(aPtA); aGroup->AddPrimitiveArray (aPntArray); + // Make an internal ring aPtA->SetType(Aspect_TOM_POINT); aPtA->SetScale(5.); aGroup->SetPrimitivesAspect(aPtA); @@ -83,11 +89,7 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) { -// if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) { -// Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10); -// Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint); -// aSelection->Add(aSp); -// } + // There is no selection of coincident - a point is selected instead of coincidence } void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol) diff --git a/src/SketcherPrs/SketcherPrs_Equal.cpp b/src/SketcherPrs/SketcherPrs_Equal.cpp index 90f705fd8..9cfd69b59 100644 --- a/src/SketcherPrs/SketcherPrs_Equal.cpp +++ b/src/SketcherPrs/SketcherPrs_Equal.cpp @@ -37,6 +37,7 @@ bool SketcherPrs_Equal::updatePoints(double theStep) const if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) return false; + // Set points of the presentation SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep); gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); @@ -52,12 +53,14 @@ void SketcherPrs_Equal::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quan Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); aGroup->SetPrimitivesAspect(aLineAspect); + // Draw first line ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); std::shared_ptr aLine = SketcherPrs_Tools::getShape(aObj); if (aLine.get() == NULL) return; drawShape(aLine, thePrs); + // Draw second line aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); aLine = SketcherPrs_Tools::getShape(aObj); if (aLine.get() == NULL) diff --git a/src/SketcherPrs/SketcherPrs_Factory.cpp b/src/SketcherPrs/SketcherPrs_Factory.cpp index 6971d7826..24914e915 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.cpp +++ b/src/SketcherPrs/SketcherPrs_Factory.cpp @@ -19,6 +19,7 @@ #include "SketcherPrs_Transformation.h" #include "SketcherPrs_Angle.h" +// Macros for constraint presentation definition #define CONSTRAINT_PRS_IMPL(NAME, CLASS) \ AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \ const std::shared_ptr& thePlane) \ @@ -40,7 +41,7 @@ CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension); CONSTRAINT_PRS_IMPL(mirrorConstraint, SketcherPrs_Mirror); CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle); - +// Non-standard constraints definition AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane) { diff --git a/src/SketcherPrs/SketcherPrs_HVDirection.cpp b/src/SketcherPrs/SketcherPrs_HVDirection.cpp index b1459205e..e7bdfdda7 100644 --- a/src/SketcherPrs/SketcherPrs_HVDirection.cpp +++ b/src/SketcherPrs/SketcherPrs_HVDirection.cpp @@ -35,6 +35,7 @@ bool SketcherPrs_HVDirection::updatePoints(double theStep) const if (SketcherPrs_Tools::getShape(aObj).get() == NULL) return false; + // Set point of the symbol SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(1, aP1); @@ -45,6 +46,7 @@ void SketcherPrs_HVDirection::drawLines(const Handle(Prs3d_Presentation)& thePrs { Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs); + // Draw constrained object Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); aGroup->SetPrimitivesAspect(aLineAspect); diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index 3ab9bc6be..24977ecee 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -56,13 +56,17 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage if (!getPoints(aPnt1, aPnt2)) return; + // compute flyout distance double aD = SketcherPrs_Tools::getFlyoutDistance(myConstraint); SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint)); SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl()); + + // Update variable aspect parameters (depending on viewer scale) myAspect->SetExtensionSize(myAspect->ArrowAspect()->Length()); myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length()); // The value of vertical aligment is sometimes changed myAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER); + AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode); } @@ -70,6 +74,7 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) { DataPtr aData = myConstraint->data(); if (myConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) { + // The constraint is length std::shared_ptr anAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::ENTITY_A())); @@ -80,6 +85,7 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) if (!aFeature || aFeature->getKind() != SketchPlugin_Line::ID()) return false; + // Get geometry of the object DataPtr aLineData = aFeature->data(); std::shared_ptr aStartPoint = std::dynamic_pointer_cast @@ -92,6 +98,7 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) return true; } else if (myConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) { + // The constraint is distance std::shared_ptr aPoint_A = SketcherPrs_Tools::getFeaturePoint( aData, SketchPlugin_Constraint::ENTITY_A(), myPlane); std::shared_ptr aPoint_B = SketcherPrs_Tools::getFeaturePoint( @@ -100,9 +107,11 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) std::shared_ptr aPnt_A; std::shared_ptr aPnt_B; if (aPoint_A && aPoint_B) { + // Both objects are points aPnt_A = aPoint_A->pnt(); aPnt_B = aPoint_B->pnt(); } else if (!aPoint_A && aPoint_B) { + // First object is line FeaturePtr aLine = SketcherPrs_Tools::getFeatureLine( aData, SketchPlugin_Constraint::ENTITY_A()); if (aLine) { @@ -110,6 +119,7 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) aPnt_A = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_B); } } else if (aPoint_A && !aPoint_B) { + // Second object is line FeaturePtr aLine = SketcherPrs_Tools::getFeatureLine( aData, SketchPlugin_Constraint::ENTITY_B()); if (aLine) { @@ -117,9 +127,10 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) aPnt_B = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_A); } } - if (!aPnt_A || !aPnt_B) + if (!aPnt_A || !aPnt_B) // Objects not found return false; + // Get points from these objects std::shared_ptr aPoint1 = myPlane->to3D(aPnt_A->x(), aPnt_A->y()); std::shared_ptr aPoint2 = myPlane->to3D(aPnt_B->x(), aPnt_B->y()); thePnt1 = aPoint1->impl(); @@ -134,6 +145,7 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) void SketcherPrs_LengthDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer theMode) { + // Map the application selection modes to standard ones Standard_Integer aMode; switch (theMode) { case 0: // we should use selection of all objects diff --git a/src/SketcherPrs/SketcherPrs_Mirror.cpp b/src/SketcherPrs/SketcherPrs_Mirror.cpp index 6ad3fb417..9719dc8cd 100644 --- a/src/SketcherPrs/SketcherPrs_Mirror.cpp +++ b/src/SketcherPrs/SketcherPrs_Mirror.cpp @@ -30,20 +30,24 @@ SketcherPrs_Mirror::SketcherPrs_Mirror(ModelAPI_Feature* theConstraint, bool SketcherPrs_Mirror::updatePoints(double theStep) const { + // Get axis of mirror ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL) return false; std::shared_ptr aData = myConstraint->data(); + // Get source objects std::shared_ptr anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B()); if (anAttrB.get() == NULL) return false; + // Get mirrored objects std::shared_ptr anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C()); if (anAttrC.get() == NULL) return false; SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); int aNb = anAttrB->size(); + // If size of source objects and mirrored ones is not equal then the constraint is not computed if (aNb != anAttrC->size()) return false; @@ -51,11 +55,13 @@ bool SketcherPrs_Mirror::updatePoints(double theStep) const int i; ObjectPtr aObj; gp_Pnt aP1; + // get position for each source object for (i = 0; i < aNb; i++) { aObj = anAttrB->object(i); aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(i + 1, aP1); } + // Get position of each mirrored object for (i = 0; i < aNb; i++) { aObj = anAttrC->object(i); aP1 = aMgr->getPosition(aObj, this, theStep); @@ -81,9 +87,6 @@ void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs, Qua Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs); - //Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); - //aGroup->SetPrimitivesAspect(aLineAspect); - // drawListOfShapes uses myDrawer for attributes definition Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1); myDrawer->SetLineAspect(aLnAspect); diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp index e80fb8f78..1b6712d9e 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.cpp +++ b/src/SketcherPrs/SketcherPrs_Parallel.cpp @@ -24,6 +24,7 @@ SketcherPrs_Parallel::SketcherPrs_Parallel(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane) : SketcherPrs_SymbolPrs(theConstraint, thePlane) { + // Create default array myPntArray = new Graphic3d_ArrayOfPoints(2); myPntArray->AddVertex(0., 0., 0.); myPntArray->AddVertex(0., 0., 0.); @@ -39,6 +40,7 @@ bool SketcherPrs_Parallel::updatePoints(double theStep) const if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) return false; + // Compute position of symbols SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep); gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); @@ -55,6 +57,7 @@ void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Q Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); aGroup->SetPrimitivesAspect(aLineAspect); + // Draw constrained lines addLine(aGroup, SketchPlugin_Constraint::ENTITY_A()); addLine(aGroup, SketchPlugin_Constraint::ENTITY_B()); } diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp index ecfd72d11..dfc6964e6 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -24,6 +24,7 @@ SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(ModelAPI_Feature* theConstr const std::shared_ptr& thePlane) : SketcherPrs_SymbolPrs(theConstraint, thePlane) { + // Create default array myPntArray = new Graphic3d_ArrayOfPoints(2); myPntArray->AddVertex(0., 0., 0.); myPntArray->AddVertex(0., 0., 0.); @@ -39,6 +40,7 @@ bool SketcherPrs_Perpendicular::updatePoints(double theStep) const if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) return false; + // Compute position of symbols SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep); gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); @@ -55,6 +57,7 @@ void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& theP Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); aGroup->SetPrimitivesAspect(aLineAspect); + // Draw constrained lines addLine(aGroup, SketchPlugin_Constraint::ENTITY_A()); addLine(aGroup, SketchPlugin_Constraint::ENTITY_B()); } diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 2e361420d..1eb15216c 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -14,7 +14,7 @@ static SketcherPrs_PositionMgr* MyPosMgr = NULL; - +// The class is implemented as a singlton SketcherPrs_PositionMgr* SketcherPrs_PositionMgr::get() { if (MyPosMgr == NULL) @@ -31,15 +31,19 @@ int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs) { if (myShapes.count(theLine) == 1) { + // Find the map and add new [Presentation - Index] pair PositionsMap& aPosMap = myShapes[theLine]; if (aPosMap.count(thePrs) == 1) { + // return existing index return aPosMap[thePrs]; } else { + // Add a new [Presentation - Index] pair int aInd = aPosMap.size(); aPosMap[thePrs] = aInd; return aInd; } } else { + // Create a new map with initial index PositionsMap aPosMap; aPosMap[thePrs] = 0; myShapes[theLine] = aPosMap; @@ -71,6 +75,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, (aPnt1->z() + aPnt2->z())/2.); } else { + // this is a circle or arc double aMidParam = (aCurve->startParam() + aCurve->endParam()) / 2.; std::shared_ptr aPnt = aCurve->getPoint(aMidParam); aP = aPnt->impl(); @@ -88,10 +93,12 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, std::shared_ptr aDir = thePrs->plane()->dirX(); aVec1 = gp_Vec(aDir->impl()); } + // Compute shifting vector for a one symbol gp_Vec aShift = aVec1.Crossed(thePrs->plane()->normal()->impl()); aShift.Normalize(); aShift.Multiply(theStep * 0.8); + // Shift the position coordinate according to position index int aPos = getPositionIndex(theShape, thePrs); int aM = 1; if ((aPos % 2) == 0) { @@ -126,13 +133,17 @@ void SketcherPrs_PositionMgr::deleteConstraint(const SketcherPrs_SymbolPrs* theP { std::map::iterator aIt; std::list aToDel; + // Clear map for deleted presentation for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) { PositionsMap& aPosMap = aIt->second; if (aPosMap.count(thePrs) > 0) { + // Erase index aPosMap.erase(aPosMap.find(thePrs)); if (aPosMap.size() == 0) + // Delete the map aToDel.push_back(aIt->first); else { + // Reindex objects positions in order to avoid spaces PositionsMap::iterator aIt; int i = 0; for (aIt = aPosMap.begin(); aIt != aPosMap.end(); aIt++, i++) diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index 4a805eae7..084660754 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -29,6 +29,7 @@ SketcherPrs_Radius::SketcherPrs_Radius(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane) : AIS_RadiusDimension(MyDefCirc), myConstraint(theConstraint), myPlane(thePlane) { + // Set default values of the presentation myAspect = new Prs3d_DimensionAspect(); myAspect->MakeArrows3d(false); myAspect->MakeText3d(false); @@ -109,6 +110,7 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the void SketcherPrs_Radius::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer theMode) { + // Map the application selection modes to standard ones Standard_Integer aMode; switch (theMode) { case 0: // we should use selection of all objects diff --git a/src/SketcherPrs/SketcherPrs_Rigid.cpp b/src/SketcherPrs/SketcherPrs_Rigid.cpp index 7ef19eef9..2fc417fed 100644 --- a/src/SketcherPrs/SketcherPrs_Rigid.cpp +++ b/src/SketcherPrs/SketcherPrs_Rigid.cpp @@ -41,6 +41,7 @@ SketcherPrs_Rigid::SketcherPrs_Rigid(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane) : SketcherPrs_SymbolPrs(theConstraint, thePlane) { + // Set default points array myPntArray = new Graphic3d_ArrayOfPoints(1); myPntArray->AddVertex(0., 0., 0.); } @@ -52,6 +53,7 @@ bool SketcherPrs_Rigid::updatePoints(double theStep) const std::shared_ptr anAttr = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); AttributePtr aRefAttr = anAttr->attr(); if (anAttr->isObject()) { + // The constraint attached to an object ObjectPtr aObj = anAttr->object(); if (SketcherPrs_Tools::getShape(aObj).get() == NULL) return false; @@ -60,6 +62,7 @@ bool SketcherPrs_Rigid::updatePoints(double theStep) const gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(1, aP1); } else { + // The constraint attached to a point std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_A()); if (aPnt.get() == NULL) return false; @@ -76,14 +79,17 @@ void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quan FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); std::shared_ptr aShape; if (aFeature.get()) { + // If constraint attached to a feature const std::list& aResults = aFeature->results(); std::list::const_iterator aIt; + // Find a shape for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) { aShape = (*aIt)->shape(); if (aShape->isEdge()) break; } } else { + // Else it is a result aShape = SketcherPrs_Tools::getShape(aObj); } if (aShape.get() == NULL) diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index 05fa43cf8..b66ecbd03 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -257,6 +257,7 @@ SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(ModelAPI_Feature* theConstraint, SketcherPrs_SymbolPrs::~SketcherPrs_SymbolPrs() { SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); + // Empty memory in position manager aMgr->deleteConstraint(this); } @@ -269,6 +270,7 @@ Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon() if (myIconsMap.count(iconName()) == 1) { return myIconsMap[iconName()]; } + // Load icon for the presentation char* aEnv = getenv("NEWGEOM_ROOT_DIR"); if (aEnv != NULL) { TCollection_AsciiString aFile(aEnv); @@ -282,6 +284,7 @@ Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon() return aPixMap; } } + // The icon for constraint is not found static const char aMsg[] = "Error! constraint images are not found"; cout< aPnt1 = aEdge->firstPoint(); std::shared_ptr aPnt2 = aEdge->lastPoint(); + // Draw line by two points Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1); aLines->AddVertex(aPnt1->impl()); aLines->AddVertex(aPnt2->impl()); @@ -348,6 +353,7 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { + // Create an icon prepareAspect(); Handle(AIS_InteractiveContext) aCtx = GetContext(); @@ -357,6 +363,7 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& aDriver->UserDrawCallback() = SymbolPrsCallBack; } + // Update points with default shift value if (!updatePoints(20)) { return; } @@ -366,6 +373,7 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& myOwner = new SelectMgr_EntityOwner(this); } + // Create sensitive point for each symbol mySPoints.Clear(); for (int i = 1; i <= aNbVertex; i++) { Handle(SketcherPrs_SensitivePoint) aSP = new SketcherPrs_SensitivePoint(myOwner, i); @@ -375,6 +383,7 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); aGroup->SetPrimitivesAspect(myAspect); + // Recompute boundary box of the group Graphic3d_BndBox4f& aBnd = aGroup->ChangeBoundingBox(); gp_Pnt aVert; aBnd.Clear(); @@ -383,6 +392,7 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& aBnd.Add (Graphic3d_Vec4((float)aVert.X(), (float)aVert.Y(), (float)aVert.Z(), 1.0f)); } + // Pint the group with custom procedure (see Render) aGroup->UserDraw(this, true); // Disable frustum culling for this object by marking it as mutable @@ -415,6 +425,7 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) Handle(OpenGl_View) aView = theWorkspace->ActiveView(); double aScale = aView->Camera()->Scale(); + // Update points coordinate taking the viewer scale into account if (!updatePoints(MyDist * aScale)) return; @@ -424,6 +435,7 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) myVboAttribs = new SketcherPrs_VertexBuffer(*aAttribs); } + // Update drawing attributes if (!myVboAttribs->init(aCtx, 0, aAttribs->NbElements, aAttribs->Data(), GL_NONE, aAttribs->Stride)) { myVboAttribs->Release (aCtx.operator->()); myVboAttribs.Nullify(); @@ -445,6 +457,7 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) if (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) aLineColor = theWorkspace->HighlightColor; + // Set lighting of the symbol if (toHilight) aCtx->core11fwd->glDisable (GL_LIGHTING); else @@ -483,6 +496,7 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) void SketcherPrs_SymbolPrs::Release (OpenGl_Context* theContext) { + // Release OpenGl resources if (!myVboAttribs.IsNull()) { if (theContext) { theContext->DelayedRelease (myVboAttribs); @@ -495,16 +509,20 @@ void SketcherPrs_SymbolPrs::drawShape(const std::shared_ptr& theS const Handle(Prs3d_Presentation)& thePrs) const { if (theShape->isEdge()) { + // The shape is edge std::shared_ptr aCurve = std::shared_ptr(new GeomAPI_Curve(theShape)); if (aCurve->isLine()) { + // The shape is line GeomAdaptor_Curve aCurv(aCurve->impl(), aCurve->startParam(), aCurve->endParam()); StdPrs_Curve::Add(thePrs, aCurv, myDrawer); } else { + // The shape is circle or arc GeomAdaptor_Curve aAdaptor(aCurve->impl(), aCurve->startParam(), aCurve->endParam()); StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer); } } else if (theShape->isVertex()) { + // draw vertex std::shared_ptr aVertex = std::shared_ptr(new GeomAPI_Vertex(theShape)); std::shared_ptr aPnt = aVertex->point(); @@ -532,8 +550,7 @@ void SketcherPrs_SymbolPrs::drawListOfShapes(const std::shared_ptrBoundingBox()); } diff --git a/src/SketcherPrs/SketcherPrs_Tangent.cpp b/src/SketcherPrs/SketcherPrs_Tangent.cpp index 199eb782f..c9adc9b55 100644 --- a/src/SketcherPrs/SketcherPrs_Tangent.cpp +++ b/src/SketcherPrs/SketcherPrs_Tangent.cpp @@ -27,6 +27,7 @@ SketcherPrs_Tangent::SketcherPrs_Tangent(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane) : SketcherPrs_SymbolPrs(theConstraint, thePlane) { + // Init default points myPntArray = new Graphic3d_ArrayOfPoints(2); myPntArray->AddVertex(0., 0., 0.); myPntArray->AddVertex(0., 0., 0.); @@ -41,6 +42,7 @@ bool SketcherPrs_Tangent::updatePoints(double theStep) const if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) return false; + // Compute points coordinates SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep); gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 912ea1446..c2ccd8748 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -73,6 +73,11 @@ std::shared_ptr getPoint(ModelAPI_Feature* theFeature, } //************************************************************************************* +/// Find an attribute of the given object which corresponds to a vetrex +/// defined by a shape +/// \param theObject an object +/// \param theShape a vertex +/// \param thePlane a projection plane (sketcher plane) std::shared_ptr findGeomPoint(ObjectPtr theObject, const TopoDS_Shape& theShape, const std::shared_ptr& thePlane) @@ -129,10 +134,12 @@ std::shared_ptr getFeaturePoint(DataPtr theData, ObjectPtr anObject = anAttr->object(); aFeature = ModelAPI_Feature::feature(anObject); if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) { + // Attribute refers to a point aPointAttr = std::dynamic_pointer_cast( aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); } else { + // if the attribute refers on another object ResultPtr aRes = std::dynamic_pointer_cast(anObject); if (aRes.get()) { GeomShapePtr aShape = aRes->shape(); @@ -144,6 +151,7 @@ std::shared_ptr getFeaturePoint(DataPtr theData, } } else if (anAttr->attr()) { + // If attribute is a point aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); } } @@ -231,13 +239,13 @@ std::shared_ptr getAnchorPoint(const ModelAPI_Feature* theConstrain FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); std::shared_ptr aCenter; - if (aFeature->getKind() == SketchPlugin_Arc::ID()) { + if (aFeature->getKind() == SketchPlugin_Arc::ID()) { // arc aCenter = std::dynamic_pointer_cast( aFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt(); - } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) { + } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) { // circle aCenter = std::dynamic_pointer_cast( aFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->pnt(); - } else + } else return std::shared_ptr(); std::shared_ptr anOrigin(new GeomAPI_Pnt2d(0.0, 0.0)); diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index 481e7d96d..a7c0925b5 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -21,32 +21,45 @@ class GeomDataAPI_Point2D; namespace SketcherPrs_Tools { -/// Enumeration with modes for activation of selection custom presentations -enum SelectionModes { - /// Start of enumeration - Sel_Mode_First = 100, + /// Enumeration with modes for activation of selection custom presentations + enum SelectionModes { + /// Start of enumeration + Sel_Mode_First = 100, - /// Selection mode for all constraints exclude dimensions - Sel_Constraint, + /// Selection mode for all constraints exclude dimensions + Sel_Constraint, - /// Selection mode for whole dimension - Sel_Dimension_All, + /// Selection mode for whole dimension + Sel_Dimension_All, - /// Selection mode for line of dimension - Sel_Dimension_Line, + /// Selection mode for line of dimension + Sel_Dimension_Line, - /// Selection mode foe text of dimension - Sel_Dimension_Text -}; + /// Selection mode foe text of dimension + Sel_Dimension_Text + }; + /// Returns result object referenced by feature + /// \param theFeature a feature + /// \param theAttrName an attribute name SKETCHERPRS_EXPORT ObjectPtr getResult(ModelAPI_Feature* theFeature, const std::string& theAttrName); + /// Returns shape from result object (or NULL) + /// \param theObject a result object SKETCHERPRS_EXPORT std::shared_ptr getShape(ObjectPtr theObject); + + /// Returns point from a line feature + /// \param theFeature a line feature + /// \param theAttrName an attribute of the point SKETCHERPRS_EXPORT std::shared_ptr getPoint(ModelAPI_Feature* theFeature, const std::string& theAttrName); + + /// Returns point projected on a line + /// \param theLine a line + /// \param thePoint a projecting point SKETCHERPRS_EXPORT std::shared_ptr getProjectionPoint( const FeaturePtr theLine, const std::shared_ptr& thePoint); @@ -55,22 +68,35 @@ enum SelectionModes { const std::string& theAttribute); /// Obtain the point object from specified constraint parameter + /// \param theData a data object + /// \param theAttribute an attribute name + /// \param thePlane a projection plane (sketcher plane) SKETCHERPRS_EXPORT std::shared_ptr getFeaturePoint(DataPtr theData, const std::string& theAttribute, const std::shared_ptr& thePlane); + /// Returns value of dimension arrows size SKETCHERPRS_EXPORT double getArrowSize(); + /// Set value of dimension arrows size + /// \param theSize a size value SKETCHERPRS_EXPORT void setArrowSize(double theSize); + /// Set value of dimension text height + /// \param theHeight a height value SKETCHERPRS_EXPORT void setTextHeight(double theHeight); + /// Returns value of dimension text height SKETCHERPRS_EXPORT double getTextHeight(); + /// Returns default value of dimension text height SKETCHERPRS_EXPORT double getDefaultTextHeight(); + /// Get flayout distance of the dimension constraint + /// \param theConstraint a dimension constraint object SKETCHERPRS_EXPORT double getFlyoutDistance(const ModelAPI_Feature* theConstraint); + /// Compute anchor pint for radius dimension SKETCHERPRS_EXPORT std::shared_ptr getAnchorPoint( const ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane); diff --git a/src/SketcherPrs/SketcherPrs_Transformation.cpp b/src/SketcherPrs/SketcherPrs_Transformation.cpp index b783a7544..929148d60 100644 --- a/src/SketcherPrs/SketcherPrs_Transformation.cpp +++ b/src/SketcherPrs/SketcherPrs_Transformation.cpp @@ -38,6 +38,7 @@ SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theCons bool SketcherPrs_Transformation::updatePoints(double theStep) const { std::shared_ptr aData = myConstraint->data(); + // Get transformated objects list std::shared_ptr anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B()); if (anAttrB.get() == NULL) return false; @@ -58,6 +59,7 @@ bool SketcherPrs_Transformation::updatePoints(double theStep) const int i; ObjectPtr aObj; gp_Pnt aP1; + // Compute points of symbols for (i = 0; i < aNbB; i++) { aObj = anAttrB->object(i); aP1 = aMgr->getPosition(aObj, this, theStep); @@ -85,24 +87,29 @@ void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& the drawListOfShapes(anAttrB, thePrs); if (myConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) { + // If it is translation std::shared_ptr aStart = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID())); std::shared_ptr aEnd = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID())); if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) { + // Add start point std::shared_ptr aPnt = myPlane->to3D(aStart->x(), aStart->y()); Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl()); StdPrs_Point::Add(thePrs, aPoint, myDrawer); + // Add end point aPnt = myPlane->to3D(aEnd->x(), aEnd->y()); aPoint = new Geom_CartesianPoint(aPnt->impl()); StdPrs_Point::Add(thePrs, aPoint, myDrawer); } } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) { + // if it is rotation std::shared_ptr aCenter = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_MultiRotation::CENTER_ID())); if (aCenter.get() && aCenter->isInitialized()) { + // Show center of rotation std::shared_ptr aPnt = myPlane->to3D(aCenter->x(), aCenter->y()); Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl()); StdPrs_Point::Add(thePrs, aPoint, myDrawer);