/*========================================================================= Program: bbtk Module: $RCSfile: bbtkComplexBlackBoxDescriptor.cxx,v $ Language: C++ Date: $Date: 2008/01/22 15:02:00 $ Version: $Revision: 1.1 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ /** * \file * \brief Class bbtk::ComplexBlackBoxDescriptor : describes a ComplexBlackBox (constituents, connections) and is able to create an instance of it. */ #include "bbtkComplexBlackBoxDescriptor.h" #include "bbtkComplexBlackBox.h" //#include "bbtkFactory.h" #include "bbtkMessageManager.h" #include "bbtkUtilities.h" namespace bbtk { //======================================================================= /// Default ctor ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(const std::string& name) : BlackBoxDescriptor() { bbtkDebugMessageInc("Core",9,"ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""< of the ComplexBlackBox of which this is the descriptor BlackBox* ComplexBlackBoxDescriptor::CreateInstance(const std::string& name) { //bbtkError("ComplexBlackBoxDescriptor::CreateInstance not implemented"); bbtkDebugMessageInc("Core",5, "ComplexBlackBoxDescriptor::CreateInstance(\"" <bbClone(name); bbtkDebugDecTab("Core",5); } //======================================================================= //======================================================================= /// Adds a black box to the complex box void ComplexBlackBoxDescriptor::Add ( const std::string& type, const std::string& name ) { bbtkDebugMessageInc("Core",5, "ComplexBlackBoxDescriptor::Add(\"" <bbUnsafeGetBlackBox( name ) ) { bbtkError("a black box \""<bbAddBlackBox ( /*mFactory->Create*/ NewBlackBox(type,name) ); bbtkDebugDecTab("Core",5); } //======================================================================= //======================================================================= /// Adds a black box to the execution list void ComplexBlackBoxDescriptor::AddToExecutionList ( const std::string& box) { bbtkDebugMessageInc("Core",5, "ComplexBlackBoxDescriptor::AddToExecutionList(\"" <bbUnsafeGetBlackBox( box ); if ( !b ) { bbtkError("the black box \""<bbAddToExecutionList ( box ); bbtkDebugDecTab("Core",5); } //======================================================================= /// Connects two black boxes of the complex box void ComplexBlackBoxDescriptor::Connect ( const std::string& from, const std::string& output, const std::string& to, const std::string& input ) { bbtkDebugMessageInc("Core",5, "ComplexBlackBoxDescriptor::Connect(\"" <bbGetBlackBox( from ); if ( !bbfrom ) { bbtkError("the black box \""<bbGetBlackBox( to ); if ( !bbto ) { bbtkError("the black box \""<*/ NewConnection( bbfrom, output, bbto, input ); mPrototype->bbAddConnection(c); bbtkDebugDecTab("Core",5); } //======================================================================= //======================================================================= /// Defines an input of the complex box void ComplexBlackBoxDescriptor::DefineInput ( const std::string& name, const std::string& box, const std::string& input, const std::string& help) { bbtkDebugMessageInc("Core",5, "ComplexBlackBoxDescriptor::DefineInput(\"" <bbGetBlackBox( box ); if ( !bb ) { bbtkError("the black box \""<bbHasInput(input) ) { bbtkError("the black box \""<bbGetInputType(input))); bbtkDebugDecTab("Core",5); } //======================================================================= //======================================================================= /// Defines an output of the complex box void ComplexBlackBoxDescriptor::DefineOutput ( const std::string& name, const std::string& box, const std::string& output, const std::string& help) { bbtkDebugMessageInc("Core",5, "ComplexBlackBoxDescriptor::DefineOutput(\"" <bbGetBlackBox( box ); if ( !bb ) { bbtkError("the black box \""<bbHasOutput(output) ) { bbtkError("the black box \""<bbGetOutputType(output))); bbtkDebugDecTab("Core",5); } //======================================================================= //======================================================================= void ComplexBlackBoxDescriptor::PrintBlackBoxes() { mPrototype->bbPrintBlackBoxes(); } //======================================================================= //======================================================================= void ComplexBlackBoxDescriptor::InsertHTMLGraph( std::ofstream& s , int detail, int level, const std::string& output_dir, bool relative_link ) { this->mPrototype->bbInsertHTMLGraph( s, detail, level, false, output_dir, relative_link ); } //======================================================================= //========================================================================= void ComplexBlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s, int detail, int level, const std::string& output_dir, bool relative_link) { bbtkDebugMessageInc("Core",9, "ComplexBlackBoxDescriptor::InsertHtmlHelp() [" <
\n"; (s) << "\n"; (s) << //"Top:  "Top\n"; // (s) << "Previous: (dir), // (s) << "Up: (dir) (s) << "

"<\n"; std::string descr = GetDescription(); //Utilities::html_format(descr); std::string author = GetAuthor(); Utilities::html_format(author); (s) << "

\n"; (s) << "\n"; (s) << "\n"; std::string inc = GetScriptFileName(); if (inc.size()>0) { (s) << "\n"; } const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap(); if (B.size()) { (s) << "\n"; } (s) << "
Description : " << descr << "
Author(s) : " << author << "
Include : " << inc << "
Dependencies : "; std::set pdeps; ComplexBlackBox::BlackBoxMapType::const_iterator b; for ( b = B.begin(); b != B.end(); ++b ) { BlackBoxDescriptor* d = b->second->bbGetDescriptor(); if (pdeps.find(d) != pdeps.end()) continue; pdeps.insert(d); Package* p = d->GetPackage(); std::string name = b->second->bbGetTypeName(); std::string url; if (relative_link) url = p->GetDocRelativeURL(); else url = p->GetDocURL(); s << "" << p->GetName()<<"::"<\n"; } (s) << "
\n"; //------------- // Graph InsertHTMLGraph( s , detail,level, output_dir, relative_link); //------------- // Inputs std::string col("#CCCCFF"); // (s) << "

Inputs

\n"; (s) << "

\n"; (s) << "\n"; const BlackBoxDescriptor::InputDescriptorMapType& imap = GetInputDescriptorMap(); InputDescriptorMapType::const_iterator in; for ( in = imap.begin(); in != imap.end(); ++in ) { std::string name(in->second->GetName()); Utilities::html_format(name); std::string type("<"); type += in->second->GetTypeName(); type += ">"; Utilities::html_format(type); std::string descr(in->second->GetDescription()); //Utilities::html_format(descr); (s) << "" << "" << "\n"; } // (s) << "
Inputs
 "<
 "<
"<
\n"; //------------- // Outputs // (s) << "

Outputs

\n"; // (s) << "\n"; (s) << "\n"; const BlackBoxDescriptor::OutputDescriptorMapType& omap = GetOutputDescriptorMap(); BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o; for ( o = omap.begin(); o != omap.end(); ++o ) { std::string name(o->second->GetName()); Utilities::html_format(name); std::string type("<"); type += o->second->GetTypeName(); type += ">"; Utilities::html_format(type); std::string descr(o->second->GetDescription()); //Utilities::html_format(descr); (s) << "" << "" << "\n"; } (s) << "
Outputs
 "<
 "<
"<
\n"; //------------ // End bbtkDebugDecTab("Core",9); } //========================================================================= //======================================================================= void ComplexBlackBoxDescriptor::GetHelp(bool full) const { if (full) bbtkMessage("Help",1,"Complex Black Box <"<< GetPackage()->GetName()<<"::" <"<second->GetName().size()>namelmax) namelmax = i->second->GetName().size(); if (i->second->GetTypeName().size()>typelmax) typelmax = i->second->GetTypeName().size(); } OutputDescriptorMapType::const_iterator o; if (full) { for ( o = mOutput.begin(); o != mOutput.end(); ++o ) { if (o->second->GetName().size()>namelmax) namelmax = o->second->GetName().size(); if (o->second->GetTypeName().size()>typelmax) typelmax = o->second->GetTypeName().size(); } } // for ( i = mInput.begin(); i != mInput.end(); ++i ) { std::string name(i->second->GetName()); name += "'"; name.append(1+namelmax-name.size(),' '); std::string type(i->second->GetTypeName()); type += ">"; type.append(1+typelmax-type.size(),' '); bbtkMessage("Help",1, " '"<second->GetDescription()<second->GetName()); name += "'"; name.append(1+namelmax-name.size(),' '); std::string type(o->second->GetTypeName()); type += ">"; type.append(1+typelmax-type.size(),' '); bbtkMessage("Help",1, " '"<second->GetDescription()<bbGetBlackBoxMap(); if (B.size()) bbtkMessage("Help",1," * Boxes : "<second->bbGetName()<< "' <" << b->second->bbGetDescriptor()->GetPackage()->GetName() <<"::" <second->bbGetTypeName()<<">"<