1 // File : FrontTrack_Utils.cxx
2 // Created : Tue Apr 25 17:28:58 2017
3 // Author : Edward AGAPOV (eap)
5 #include "FrontTrack_Utils.hxx"
8 #include <XAO_Group.hxx>
11 #include <boost/filesystem.hpp>
13 namespace boofs = boost::filesystem;
15 //================================================================================
17 * \brief Check if a file exists
19 //================================================================================
21 bool FT_Utils::fileExists( const std::string& path )
26 boost::system::error_code err;
27 bool res = boofs::exists( path, err );
29 return err ? false : res;
32 //================================================================================
34 * \brief Check if a file can be created/overwritten
36 //================================================================================
38 bool FT_Utils::canWrite( const std::string& path )
46 HANDLE file = CreateFile( path.c_str(), // name of the write
47 GENERIC_WRITE, // open for writing
49 NULL, // default security
50 OPEN_ALWAYS, // CREATE NEW or OPEN EXISTING
51 FILE_ATTRIBUTE_NORMAL, // normal file
52 NULL); // no attr. template
53 can = ( file != INVALID_HANDLE_VALUE );
58 int file = ::open( path.c_str(),
60 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ); // rw-r--r--
68 //================================================================================
70 * \brief Make a map of XAO groups
72 //================================================================================
74 FT_Utils::XaoGroups::XaoGroups( const XAO::Xao* theXao )
76 XAO::Xao* xao = const_cast< XAO::Xao* >( theXao );
78 for ( int iG = 0; iG < theXao->countGroups(); ++iG )
80 XAO::Group* group = xao->getGroup( iG );
82 if ( group->getDimension() == 1 )
84 _xaoGroups[ 0 ].insert( std::make_pair( group->getName(), group ));
86 else if ( group->getDimension() == 2 )
88 _xaoGroups[ 1 ].insert( std::make_pair( group->getName(), group ));
92 //================================================================================
94 * \brief Return FT_Projector's by a group name
95 * \param [in] groupName - the group name
96 * \param [in] dim - the group dimension
97 * \param [in] allProjectors - the projector of all shapes of \a dim dimension
98 * \param [out] groupProjectors - projectors to shapes of the group
99 * \return int - number of found shapes
101 //================================================================================
103 int FT_Utils::XaoGroups::getProjectors( const std::string& groupName,
105 const std::vector< FT_Projector > & allProjectors,
106 std::vector< const FT_Projector* > & groupProjectors) const
108 // get namesake groups
110 const TGroupByNameMap* groupMap = 0;
112 groupMap = &_xaoGroups[ 0 ];
114 groupMap = &_xaoGroups[ 1 ];
118 TGroupByNameMap::const_iterator name2gr = groupMap->find( groupName );
119 if ( name2gr == groupMap->end() )
122 std::vector< XAO::Group* > groups;
123 groups.push_back( name2gr->second );
125 for ( ++name2gr; name2gr != groupMap->end(); ++name2gr )
127 if ( name2gr->second->getName() == groupName )
128 groups.push_back( name2gr->second );
136 for ( size_t i = 0; i < groups.size(); ++i )
138 // IDs in XAO correspond to indices of allProjectors
139 std::set<int>::iterator id = groups[i]->begin(), end = groups[i]->end();
140 for ( ; id != end; ++id, ++nbFound )
141 if ( *id < (int) allProjectors.size() )
142 groupProjectors.push_back ( & allProjectors[ *id ]);