1 // Copyright (C) 2017-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : FrontTrack_Utils.cxx
20 // Created : Tue Apr 25 17:28:58 2017
21 // Author : Edward AGAPOV (eap)
23 #include "FrontTrack_Utils.hxx"
25 #include <XAO_Xao.hxx>
26 #include <XAO_Group.hxx>
29 #include <boost/filesystem.hpp>
31 namespace boofs = boost::filesystem;
33 //================================================================================
35 * \brief Check if a file exists
37 //================================================================================
39 bool FT_Utils::fileExists( const std::string& path )
44 boost::system::error_code err;
45 bool res = boofs::exists( path, err );
47 return err ? false : res;
50 //================================================================================
52 * \brief Check if a file can be created/overwritten
54 //================================================================================
56 bool FT_Utils::canWrite( const std::string& path )
64 HANDLE file = CreateFile( path.c_str(), // name of the write
65 GENERIC_WRITE, // open for writing
67 NULL, // default security
68 OPEN_ALWAYS, // CREATE NEW or OPEN EXISTING
69 FILE_ATTRIBUTE_NORMAL, // normal file
70 NULL); // no attr. template
71 can = ( file != INVALID_HANDLE_VALUE );
76 int file = ::open( path.c_str(),
78 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ); // rw-r--r--
86 //================================================================================
88 * \brief Make a map of XAO groups
90 //================================================================================
92 FT_Utils::XaoGroups::XaoGroups( const XAO::Xao* theXao )
94 XAO::Xao* xao = const_cast< XAO::Xao* >( theXao );
96 for ( int iG = 0; iG < theXao->countGroups(); ++iG )
98 XAO::Group* group = xao->getGroup( iG );
100 if ( group->getDimension() == 1 )
102 _xaoGroups[ 0 ].insert( std::make_pair( group->getName(), group ));
104 else if ( group->getDimension() == 2 )
106 _xaoGroups[ 1 ].insert( std::make_pair( group->getName(), group ));
110 //================================================================================
112 * \brief Return FT_Projector's by a group name
113 * \param [in] groupName - the group name
114 * \param [in] dim - the group dimension
115 * \param [in] allProjectors - the projector of all shapes of \a dim dimension
116 * \param [out] groupProjectors - projectors to shapes of the group
117 * \return int - number of found shapes
119 //================================================================================
121 int FT_Utils::XaoGroups::getProjectors( const std::string& groupName,
123 const std::vector< FT_Projector > & allProjectors,
124 std::vector< const FT_Projector* > & groupProjectors) const
126 // get namesake groups
128 const TGroupByNameMap* groupMap = 0;
130 groupMap = &_xaoGroups[ 0 ];
132 groupMap = &_xaoGroups[ 1 ];
136 TGroupByNameMap::const_iterator name2gr = groupMap->find( groupName );
137 if ( name2gr == groupMap->end() )
140 std::vector< XAO::Group* > groups;
141 groups.push_back( name2gr->second );
143 for ( ++name2gr; name2gr != groupMap->end(); ++name2gr )
145 if ( name2gr->second->getName() == groupName )
146 groups.push_back( name2gr->second );
154 for ( size_t i = 0; i < groups.size(); ++i )
156 // IDs in XAO correspond to indices of allProjectors
157 std::set<int>::iterator id = groups[i]->begin(), end = groups[i]->end();
158 for ( ; id != end; ++id, ++nbFound )
159 if ( *id < (int) allProjectors.size() )
160 groupProjectors.push_back ( & allProjectors[ *id ]);