Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 09:05:18

0001 // Created on: 2015-05-14
0002 // Created by: Ilya Novikov
0003 // Copyright (c) 2000-2015 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _XCAFDoc_Editor_HeaderFile
0017 #define _XCAFDoc_Editor_HeaderFile
0018 
0019 #include <TDataStd_Name.hxx>
0020 #include <TDF_Label.hxx>
0021 #include <NCollection_DataMap.hxx>
0022 #include <NCollection_Map.hxx>
0023 #include <NCollection_Sequence.hxx>
0024 
0025 class XCAFDoc_VisMaterial;
0026 class XCAFDoc_ShapeTool;
0027 
0028 //! Tool for edit structure of document.
0029 class XCAFDoc_Editor
0030 {
0031 public:
0032   DEFINE_STANDARD_ALLOC
0033 
0034   //! Converts shape (compound/compsolid/shell/wire) to assembly.
0035   //! @param[in] theDoc input document
0036   //! @param[in] theShape input shape label
0037   //! @param[in] theRecursively recursively expand a compound subshape
0038   //! @return True if shape successfully expanded
0039   Standard_EXPORT static bool Expand(const TDF_Label& theDoc,
0040                                      const TDF_Label& theShape,
0041                                      const bool       theRecursively = true);
0042 
0043   //! Converts all compounds shapes in the document to assembly
0044   //! @param[in] theDoc input document
0045   //! @param[in] theRecursively recursively expand a compound subshape
0046   //! @return True if shape successfully expanded
0047   Standard_EXPORT static bool Expand(const TDF_Label& theDoc, const bool theRecursively = true);
0048 
0049   //! Clones all labels to a new position, keeping the structure with all the attributes
0050   //! @param[in] theSrcLabels original labels to copy from
0051   //! @param[in] theDstLabel label to set result as a component of or a main document's label to
0052   //! simply set new shape
0053   //! @param[in] theIsNoVisMat get a VisMaterial attributes as is or convert to color
0054   //! @return True if shape successfully extracted
0055   Standard_EXPORT static bool Extract(const NCollection_Sequence<TDF_Label>& theSrcLabels,
0056                                       const TDF_Label&                       theDstLabel,
0057                                       const bool                             theIsNoVisMat = false);
0058 
0059   //! Clones the label to a new position, keeping the structure with all the attributes
0060   //! @param[in] theSrcLabel original label to copy from
0061   //! @param[in] theDstLabel label to set result as a component of or a main document's label to
0062   //! simply set new shape
0063   //! @param[in] theIsNoVisMat get a VisMaterial attributes as is or convert to color
0064   //! @return True if shape successfully extracted
0065   Standard_EXPORT static bool Extract(const TDF_Label& theSrcLabel,
0066                                       const TDF_Label& theDstLabel,
0067                                       const bool       theIsNoVisMat = false);
0068 
0069   //! Copies shapes label with keeping of shape structure (recursively)
0070   //! @param[in] theSrcLabel original label to copy from
0071   //! @param[in] theSrcShapeTool shape tool to get
0072   //! @param[in] theDstShapeTool shape tool to set
0073   //! @param[out] theMap relating map of the original shapes label and labels created from them
0074   //! @return result shape label
0075   Standard_EXPORT static TDF_Label CloneShapeLabel(
0076     const TDF_Label&                           theSrcLabel,
0077     const occ::handle<XCAFDoc_ShapeTool>&      theSrcShapeTool,
0078     const occ::handle<XCAFDoc_ShapeTool>&      theDstShapeTool,
0079     NCollection_DataMap<TDF_Label, TDF_Label>& theMap);
0080 
0081   //! Copies metadata contains from the source label to the destination label.
0082   //! Protected against creating a new label for non-existent tools
0083   //! @param[in] theSrcLabel original label to copy from
0084   //! @param[in] theDstLabel destination shape label to set attributes
0085   //! @param[in] theVisMatMap relating map of the original VisMaterial and created. Can be NULL for
0086   //! the same document
0087   //! @param[in] theToCopyColor copying visible value and shape color (handled all color type)
0088   //! @param[in] theToCopyLayer copying layer
0089   //! @param[in] theToCopyMaterial copying  material
0090   //! @param[in] theToCopyVisMaterial copying visual material
0091   //! @param[in] theToCopyAttributes copying of other node attributes, for example, a shape's
0092   //! property
0093   Standard_EXPORT static void CloneMetaData(
0094     const TDF_Label& theSrcLabel,
0095     const TDF_Label& theDstLabel,
0096     NCollection_DataMap<occ::handle<XCAFDoc_VisMaterial>, occ::handle<XCAFDoc_VisMaterial>>*
0097                theVisMatMap,
0098     const bool theToCopyColor       = true,
0099     const bool theToCopyLayer       = true,
0100     const bool theToCopyMaterial    = true,
0101     const bool theToCopyVisMaterial = true,
0102     const bool theToCopyAttributes  = true);
0103 
0104   //! Gets shape labels that has down relation with the input label.
0105   //! @param[in] theLabel input label
0106   //! @param[out] theRelatedLabels output labels
0107   Standard_EXPORT static void GetParentShapeLabels(const TDF_Label&            theLabel,
0108                                                    NCollection_Map<TDF_Label>& theRelatedLabels);
0109 
0110   //! Gets shape labels that has up relation with the input label.
0111   //! @param[in] theLabel input label
0112   //! @param[out] theRelatedLabels output labels
0113   Standard_EXPORT static void GetChildShapeLabels(const TDF_Label&            theLabel,
0114                                                   NCollection_Map<TDF_Label>& theRelatedLabels);
0115 
0116   //! Filters original shape tree with keeping structure.
0117   //! The result will include the full label hierarchy lower then input labels.
0118   //! Any higher hierarchy labels will be filtered to keep only necessary labels.
0119   //! All not related shape labels with input will be cleared (all attributes will be removed).
0120   //!
0121   //! The result impact directly into original document and existed shape labels.
0122   //! Attributes related to removed shape can became invalide.
0123   //! For example, GDT with relation on removed shape label(s) and without
0124   //! attachment point(s) became invalid for visualization.
0125   //!
0126   //! @param[in] theShapeTool shape tool to extract from
0127   //! @param[in] theLabelsToKeep labels to keep
0128   //! @return true if the tree was filtered successfully.
0129   Standard_EXPORT static bool FilterShapeTree(const occ::handle<XCAFDoc_ShapeTool>& theShapeTool,
0130                                               const NCollection_Map<TDF_Label>& theLabelsToKeep);
0131 
0132   //! Applies geometrical scaling to the following assembly components:
0133   //! - part geometry
0134   //! - sub-assembly/part occurrence location
0135   //! - part's centroid, area and volume attributes
0136   //! - PMIs (warnings and errors are reported if it is impossible to make changes)
0137   //! Normally, should start from a root sub-assembly, but if theForceIfNotRoot true
0138   //! scaling will be applied forcibly. If theLabel corresponds to the shape tool
0139   //! scaling is applied to the whole assembly.
0140   //! @param[in] theLabel starting label
0141   //! @param[in] theScaleFactor scale factor, should be positive
0142   //! @param[in] theForceIfNotRoot allows scaling of a non root assembly if true,
0143   //!                              otherwise - returns false
0144   //! @return true in case of success, otherwise - false.
0145   Standard_EXPORT static bool RescaleGeometry(const TDF_Label& theLabel,
0146                                               const double     theScaleFactor,
0147                                               const bool       theForceIfNotRoot = false);
0148 };
0149 
0150 #endif // _XCAFDoc_Editor_HeaderFile