// SPDX-License-Identifier: LGPL-2.1-or-later /**************************************************************************** * * * Copyright (c) 2024 wandererfan * * * * This file is part of FreeCAD. * * * * FreeCAD 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. * * * * FreeCAD 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 FreeCAD. If not, see * * . * * * ***************************************************************************/ #ifndef MEASURE_SHAPEFINDER_H #define MEASURE_SHAPEFINDER_H #include #include #include #include #include #include #include #include "SubnameHelper.h" namespace Measure { //! a class to hold the result of resolving a selection into the actual target object //! and traditional subElement name (Vertex1) class MeasureExport ResolveResult { public: ResolveResult(); ResolveResult( const App::DocumentObject* realTarget, const std::string& shortSubName, const App::DocumentObject* targetParent ); App::DocumentObject& getTarget() const; std::string getShortSub() const; App::DocumentObject& getTargetParent() const; private: App::SubObjectT m_target; App::DocumentObjectT m_targetParent; }; //! a class to obtain the located shape pointed at by a selection class MeasureExport ShapeFinder: public SubnameHelper { public: static TopoDS_Shape getLocatedShape( const App::DocumentObject& rootObject, const std::string& leafSub ); static Part::TopoShape getLocatedTopoShape( const App::DocumentObject& rootObject, const std::string& leafSub ); static std::pair getGlobalTransform( const App::DocumentObject& rootObject, const std::string& leafSub ); static std::pair getGlobalTransform( const App::DocumentObject* cursorObject ); static void crawlPlacementChain( std::vector& plmStack, std::vector& scaleStack, const App::DocumentObject& rootObj, const std::string& leafSub ); static ResolveResult resolveSelection( const App::DocumentObject& selectObj, const std::string& selectLongSub ); static Base::Placement getPlacement(const App::DocumentObject* root); static Base::Matrix4D getScale(const App::DocumentObject* root); static bool isLinkLike(const App::DocumentObject* obj); static std::string PlacementAsString(const Base::Placement& inPlacement); static std::string LocationAsString(const TopLoc_Location& location); static TopoDS_Shape transformShape( TopoDS_Shape& inShape, const Base::Placement& placement, const Base::Matrix4D& scaler ); static TopoDS_Shape stripInfiniteShapes(const TopoDS_Shape& inShape); static bool isShapeReallyNull(const TopoDS_Shape& shape); static std::pair sumTransforms( const std::vector& plmStack, const std::vector& scaleStack ); static App::DocumentObject* getLinkAttachParent(const App::DocumentObject* attachedObject); static Base::Placement getAttachedPlacement(const App::DocumentObject* cursorObject); static std::string getFullPath(const App::DocumentObject* object); static std::vector getGeometryRootObjects(const App::Document* doc); static std::vector> getGeometryPathsFromOutList( const App::DocumentObject* object ); private: static bool ignoreModule(const std::string& moduleName); static bool ignoreObject(const App::DocumentObject* object); static bool ignoreLinkAttachedObject( const App::DocumentObject* object, const App::DocumentObject* inlistObject ); static std::vector tidyInList( const std::vector& inlist ); static std::vector tidyInListAttachment( const App::DocumentObject* owner, const std::vector& inlist ); }; } // namespace Measure #endif // MEASURE_SHAPEFINDER_H