1515
1616#include " RobotAssembler.h"
1717
18+ // #define USE_OLD_OPTION 0
1819// #define IRSL_DEBUG
1920#include " irsl_debug.h"
2021
2122using namespace cnoid ;
2223
24+ #ifdef USE_OLD_OPTION
2325namespace po = boost::program_options;
26+ #endif
2427namespace ra = cnoid::robot_assembler;
2528namespace filesystem = cnoid::stdx::filesystem;
2629
@@ -36,9 +39,14 @@ class RobotAssemblerPlugin::Impl
3639
3740 RobotAssemblerPlugin *self;
3841
42+ #ifdef USE_OLD_OPTION
3943 void onSigOptionsParsed (po::variables_map& variables);
44+ #else
45+ void onSigOptionsParsed (OptionManager *_om);
46+ #endif
4047};
4148}
49+ #ifdef USE_OLD_OPTION
4250void RobotAssemblerPlugin::Impl::onSigOptionsParsed (po::variables_map& variables)
4351{
4452 // // Order of initializaiton
@@ -123,6 +131,60 @@ void RobotAssemblerPlugin::Impl::onSigOptionsParsed(po::variables_map& variables
123131 }
124132 }
125133}
134+ #else
135+ void RobotAssemblerPlugin::Impl::onSigOptionsParsed (OptionManager *_om)
136+ {
137+ if (_om->count (" --assembler" )) {
138+ AssemblerManager *manager = AssemblerManager::instance ();
139+ {
140+ auto op = _om->get_option (" --assembler" );
141+ std::string fname_ = op->as <std::string>();
142+ if (!!manager) {
143+ DEBUG_STREAM (" robot_assembler config file: " << fname_);
144+ manager->loadSettings (fname_);
145+ }
146+ }
147+ if (_om->count (" --assembler-robot" )) {
148+ auto op = _om->get_option (" --assembler-robot" );
149+ std::string fname_ = op->as <std::string>();
150+ if (!!manager) {
151+ DEBUG_STREAM (" .roboasm file: " << fname_);
152+ manager->loadRoboasm (fname_);
153+ }
154+ }
155+ if (_om->count (" original-project" )) {
156+ auto op = _om->get_option (" --original-project" );
157+ std::string fname_ = op->as <std::string>();
158+ if (!!manager) {
159+ DEBUG_STREAM (" original-project : " << fname_);
160+ manager->setOriginalProject (fname_);
161+ }
162+ }
163+ if (_om->count (" --project" )) {
164+ auto op = _om->get_option (" --project" );
165+ std::vector<std::string> _fls = op->as <std::vector<std::string>>();
166+ DEBUG_STREAM (" project : " );
167+ for (int i = 0 ; i < _fls.size (); i++) {
168+ DEBUG_STREAM (" " << i << " : " << _fls[i]);
169+ }
170+ if (!!manager) {
171+ manager->setAssemblerProject (_fls[0 ]);
172+ }
173+ }
174+ if (_om->count (" --input-file" )) {
175+ auto op = _om->get_option (" --input-file" );
176+ std::vector<std::string> _fls = op->as <std::vector<std::string>>();
177+ DEBUG_STREAM (" input-file : " );
178+ for (int i = 0 ; i < _fls.size (); i++) {
179+ DEBUG_STREAM (" " << i << " : " << _fls[i]);
180+ }
181+ if (!!manager) {
182+ manager->setAssemblerProject (_fls[0 ]);
183+ }
184+ }
185+ }
186+ }
187+ #endif
126188RobotAssemblerPlugin* RobotAssemblerPlugin::instance ()
127189{
128190 return instance_;
@@ -143,13 +205,22 @@ RobotAssemblerPlugin::~RobotAssemblerPlugin()
143205bool RobotAssemblerPlugin::initialize ()
144206{
145207 DEBUG_PRINT ();
208+ #ifdef USE_OLD_OPTION
146209 OptionManager& om = this ->optionManager ();
147210 om.addOption (" assembler" , po::value<std::string>(), " load robot_assembler config file" );
148211 om.addOption (" assembler-robot" , po::value<std::string>(), " load robot_assembler .roboasm file" );
149212 om.addOption (" original-project" , po::value<std::string>(), " project file for original choreonoid" );
150213 // om.sigOptionsParsed(1).connect(onSigOptionsParsed);
151214 om.sigOptionsParsed (1 ).connect (
152215 [&](po::variables_map& _v) { impl->onSigOptionsParsed (_v); } );
216+ #else
217+ auto om = OptionManager::instance ();
218+ om->add_option (" assembler,--assembler" , " load robot_assembler config file" );
219+ om->add_option (" assembler-robot,--assembler-robot" , " load robot_assembler .roboasm file" );
220+ om->add_option (" original-project,--original-project" , " project file for original choreonoid" );
221+ om->sigOptionsParsed (1 ).connect (
222+ [&](OptionManager *_om) { impl->onSigOptionsParsed (_om); } );
223+ #endif
153224
154225 // classes
155226 AssemblerItem::initializeClass (this );
0 commit comments