X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_AISObject.cpp;h=45f57fa5a241a7a8b3012b8d0fe7c5f8a8d65b2e;hb=026f5b80ebe2c718246d80f9cb9bea3887406c12;hp=f4ae420490bada6d8d4b177459ba93c67198fb94;hpb=d11d4ba5e291b60c458d15e11081515990cc27fe;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index f4ae42049..45f57fa5a 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomAPI_AISObject.cpp -// Created: 25 Jun 2014 -// Author: Artem ZHIDKOV +// Copyright (C) 2014-2019 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include @@ -41,6 +54,17 @@ GeomAPI_AISObject::GeomAPI_AISObject() { } +GeomAPI_AISObject::~GeomAPI_AISObject() +{ + if (!empty()) { + // This is necessary for correct deletion of Handle entity. + // Without this Handle does not decremented counter to 0 + Handle(AIS_InteractiveObject) *anAIS = implPtr(); + anAIS->Nullify(); + } +} + + void GeomAPI_AISObject::createShape(std::shared_ptr theShape) { const TopoDS_Shape& aTDS = @@ -60,8 +84,32 @@ void GeomAPI_AISObject::createShape(std::shared_ptr theShape) aShapeAIS->Set(aTDS); aShapeAIS->Redisplay(Standard_True); } - } else - setImpl(new Handle(AIS_InteractiveObject)(new AIS_Shape(aTDS))); + } else { + // Set default point as a '+' symbol + Handle(AIS_Shape) aShape = new AIS_Shape(aTDS); + Handle(Prs3d_Drawer) aDrawer = aShape->Attributes(); + if (aDrawer->HasOwnPointAspect()) + aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS); + else + aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.)); + setImpl(new Handle(AIS_InteractiveObject)(aShape)); + } +} + +std::shared_ptr GeomAPI_AISObject::getShape() const +{ + std::shared_ptr aResult; + + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); + if (aShapeAIS) { + std::shared_ptr aResult(new GeomAPI_Shape); + aResult->setImpl(new TopoDS_Shape(aShapeAIS->Shape())); + return aResult; + } + } + return std::shared_ptr(); } void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoint, @@ -122,6 +170,21 @@ void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoin } } +bool GeomAPI_AISObject::isEmptyDistanceGeometry() +{ + bool anEmpty = false; + + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + if (!aDimAIS.IsNull()) { + anEmpty = !aDimAIS->IsValid(); + } + } + + return anEmpty; +} + void GeomAPI_AISObject::createRadius(std::shared_ptr theCircle, std::shared_ptr theFlyoutPoint, double theRadius) @@ -131,7 +194,7 @@ void GeomAPI_AISObject::createRadius(std::shared_ptr theCircle, // TODO: a bug in AIS_RadiusDimension: // The anchor point can't be myCirc.Location() - an exception is raised. // But we need exactly this case... - // We want to show a radius dimension starting from the circle centre and + // We want to show a radius dimension starting from the circle centre and // ending at the user-defined point. // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all. std::shared_ptr anAnchor = theCircle->project(theFlyoutPoint); @@ -261,13 +324,25 @@ void GeomAPI_AISObject::setColor(const int& theColor) if (anAIS.IsNull()) return; Quantity_Color aColor((Quantity_NameOfColor) theColor); - anAIS->SetColor(aColor); Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->DimensionAspect()->SetCommonColor(aColor); } Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); - aContext->SetColor(anAIS, aColor, false); + if (!aContext.IsNull()) + aContext->SetColor(anAIS, aColor, false); + else + anAIS->SetColor(aColor); +} + +double GeomAPI_AISObject::width() +{ + double aWidth = 0.0; + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + aWidth = anAIS->Width(); + } + return aWidth; } bool GeomAPI_AISObject::setWidth(const double& theWidth) @@ -294,13 +369,15 @@ bool GeomAPI_AISObject::setColor(int theR, int theG, int theB) if (aColor.IsEqual(aCurrentColor)) return false; - anAIS->SetColor(aColor); Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->DimensionAspect()->SetCommonColor(aColor); } Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); - aContext->SetColor(anAIS, aColor, false); + if (!aContext.IsNull()) + aContext->SetColor(anAIS, aColor, false); + else + anAIS->SetColor(aColor); return true; } @@ -310,12 +387,85 @@ void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB) if (anAIS.IsNull()) return; - Quantity_Color aColor = anAIS->Color(); - theR = aColor.Red()*255.; - theG = aColor.Green()*255.; - theB = aColor.Blue()*255.; + Quantity_Color aColor; + anAIS->Color(aColor); + theR = (int)(aColor.Red()*255.); + theG = (int)(aColor.Green()*255.); + theB = (int)(aColor.Blue()*255.); +} + +bool GeomAPI_AISObject::setDeflection(const double theDeflection) +{ + bool isModified = false; + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); + if (!anAISShape.IsNull()) { + Standard_Real aCoefficient, aPreviousCoefficient; + anAISShape->OwnDeviationCoefficient(aCoefficient, aPreviousCoefficient); + if (fabs(aCoefficient-theDeflection) > Precision::Confusion()) { + isModified = true; + anAISShape->SetOwnDeviationCoefficient(theDeflection); + Handle(Prs3d_Drawer) aDrawer = anAISShape->DynamicHilightAttributes(); + if (!aDrawer.IsNull()) { + aDrawer->SetDeviationCoefficient(theDeflection); + } + // redisplay is necessary here to update presentation in all modes + // Standard True flag. Displayer uses Standard False flag. If it will be changed in + // displayer, redisplay here will not be necessary. But performance should be checked. + anAISShape->Redisplay(Standard_True); + } + } + } + return isModified; } +double GeomAPI_AISObject::getDeflection() const +{ + double aDeflection = -1; + + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes(); + aDeflection = aDrawer->DeviationCoefficient(); + } + return aDeflection; +} + +bool GeomAPI_AISObject::setTransparency(const double theTransparency) +{ + bool isModified = false; + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); + if (!anAISShape.IsNull()) { + Standard_Real aPreviousValue = anAISShape->Transparency(); + if (fabs(aPreviousValue - theTransparency) > Precision::Confusion()) { + anAISShape->SetTransparency(theTransparency); + //>SetOwnDeviationCoefficient(theTransparency); + isModified = true; + // redisplay is necessary here to update presentation in all modes + // Standard True flag. Displayer uses Standard False flag. If it will be changed in + // displayer, redisplay here will not be necessary. But performance should be checked. + anAISShape->Redisplay(Standard_True); + } + } + } + return isModified; +} + +double GeomAPI_AISObject::getTransparency() const +{ + double aTransparency = 0; + + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + aTransparency = anAIS->Transparency(); + } + return aTransparency; +} + + bool GeomAPI_AISObject::empty() const { Handle(AIS_InteractiveObject) anAIS = const_cast(this) @@ -332,7 +482,9 @@ int GeomAPI_AISObject::getShapeType() const if (!anAIS.IsNull()) { Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anAIS); if (!aAISShape.IsNull()) { - return aAISShape->Shape().ShapeType(); + const TopoDS_Shape aShape = aAISShape->Shape(); + if (!aShape.IsNull()) + return aShape.ShapeType(); } } return -1; @@ -342,8 +494,8 @@ void GeomAPI_AISObject::setPointMarker(int theType, double theScale) { Handle(AIS_InteractiveObject) anAIS = impl(); if (!anAIS.IsNull()) { - Handle(AIS_Drawer) aDrawer = anAIS->Attributes(); - if (aDrawer->HasPointAspect()) { + Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes(); + if (aDrawer->HasOwnPointAspect()) { Handle(Prs3d_PointAspect) aPA = aDrawer->PointAspect(); aPA->SetTypeOfMarker((Aspect_TypeOfMarker)theType); aPA->SetScale(theScale); @@ -359,29 +511,28 @@ bool GeomAPI_AISObject::setLineStyle(int theStyle) bool isChanged = false; Handle(AIS_InteractiveObject) anAIS = impl(); if (!anAIS.IsNull()) { - Handle(AIS_Drawer) aDrawer = anAIS->Attributes(); + Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes(); Handle(Prs3d_LineAspect) aLineAspect; Aspect_TypeOfLine aType = (Aspect_TypeOfLine)theStyle; - if (aDrawer->HasLineAspect()) { + if (aDrawer->HasOwnLineAspect()) { aLineAspect = aDrawer->LineAspect(); } - if (aDrawer->HasWireAspect()) { + if (aDrawer->HasOwnWireAspect()) { aLineAspect = aDrawer->WireAspect(); } - Quantity_Color aCurrentColor; - Aspect_TypeOfLine aCurrentType; - Standard_Real aCurrentWidth; - aLineAspect->Aspect()->Values(aCurrentColor, aCurrentType, aCurrentWidth); - isChanged = aType != aCurrentType; - if (isChanged) { - aLineAspect->SetTypeOfLine(aType); + if (!aLineAspect.IsNull()) { + Handle(Graphic3d_AspectLine3d) aGraphicAspect = aLineAspect->Aspect(); + Aspect_TypeOfLine aCurrentType = aGraphicAspect->Type(); + isChanged = aType != aCurrentType; + if (isChanged) { + aLineAspect->SetTypeOfLine(aType); + } } } return isChanged; } - bool GeomAPI_AISObject::setTransparensy(double theVal) { bool isChanged = false; @@ -393,6 +544,8 @@ bool GeomAPI_AISObject::setTransparensy(double theVal) isChanged = aCurrentValue != theVal; if (isChanged) aContext->SetTransparency(anAIS, theVal, false); + } else { + anAIS->SetTransparency(theVal); } } return isChanged;