X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomData%2FGeomData_Dir.cpp;h=bfb86c89f6cd75b85c181734f054234762ae23a1;hb=57f95f226733dbd01fcd42c4b1f842c71560b7d7;hp=44f04fe307900b6867a4bba70a6d7bd480b7c984;hpb=8a9a3ae0793503abf21a2c1b0a08d47d85449fc4;p=modules%2Fshaper.git diff --git a/src/GeomData/GeomData_Dir.cpp b/src/GeomData/GeomData_Dir.cpp index 44f04fe30..bfb86c89f 100644 --- a/src/GeomData/GeomData_Dir.cpp +++ b/src/GeomData/GeomData_Dir.cpp @@ -1,28 +1,41 @@ -// File: GeomData_Dir.cxx -// Created: 2 Apr 2014 -// Author: Mikhail PONIKAROV +// Copyright (C) 2014-2022 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 "GeomData_Dir.h" -#include "GeomAPI_Dir.h" +#include +#include #include -#include "Model_Events.h" -#include - -using namespace std; +#include +#include void GeomData_Dir::setValue(const double theX, const double theY, const double theZ) { - if (myCoords->Value(0) != theX || myCoords->Value(1) != theY || myCoords->Value(2) != theZ) { + if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY + || myCoords->Value(2) != theZ) { myCoords->SetValue(0, theX); myCoords->SetValue(1, theY); myCoords->SetValue(2, theZ); - static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); - Model_FeatureUpdatedMessage aMsg(owner(), anEvent); - Events_Loop::loop()->send(aMsg); + owner()->data()->sendAttributeUpdated(this); } } -void GeomData_Dir::setValue(const boost::shared_ptr& theDir) +void GeomData_Dir::setValue(const std::shared_ptr& theDir) { setValue(theDir->x(), theDir->y(), theDir->z()); } @@ -42,17 +55,56 @@ double GeomData_Dir::z() const return myCoords->Value(2); } -boost::shared_ptr GeomData_Dir::dir() +std::shared_ptr GeomData_Dir::dir() +{ + return std::shared_ptr( + new GeomAPI_Dir(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2))); +} + +std::shared_ptr GeomData_Dir::xyz() { - return boost::shared_ptr(new GeomAPI_Dir( - myCoords->Value(0), myCoords->Value(1), myCoords->Value(2))); + return std::shared_ptr( + new GeomAPI_XYZ(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2))); } GeomData_Dir::GeomData_Dir(TDF_Label& theLabel) { - // check the attribute could be already presented in this doc (after load document) - if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) { + myLab = theLabel; + reinit(); +} + +void GeomData_Dir::reinit() +{ + myIsInitialized = myLab.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True; + if (!myIsInitialized) { // create attribute: not initialized by value yet, just zero - myCoords = TDataStd_RealArray::Set(theLabel, 0, 2); + myCoords = TDataStd_RealArray::Set(myLab, 0, 2); + myIsInitialized = true; + } +} + +void GeomData_Dir::reset() +{ + if (myLab.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) { + // invalidate values of the direction + myCoords->SetValue(0, 0.0); + myCoords->SetValue(1, 0.0); + myCoords->SetValue(2, 0.0); + } + GeomDataAPI_Dir::reset(); +} + +bool GeomData_Dir::isInitialized() +{ + // Check once again the direction is initialized. + // Use case (bos #18905): draw a sketch, click "Change sketch plane", then abort it. + // myIsInitialized value is dropped to false, thus recheck. + // Additionally verify the values are valid. + // Use case (bos #24206): start a sketch, highlight a coordinate plane, then click anywhere + // in empty space. Sketch features in menu appears and can be selected. + if (!myIsInitialized) { + myIsInitialized = myLab.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True + && myCoords->Value(0) != 0.0 && myCoords->Value(1) != 0.0 && myCoords->Value(2) != 0.0; } + return ModelAPI_Attribute::isInitialized(); }