/*========================================================================= Program: bbtk Module: $RCSfile: bbtkComplexBlackBoxDescriptor.cxx,v $ Language: C++ Date: $Date: 2009/12/08 14:10:36 $ Version: $Revision: 1.21 $ =========================================================================*/ /* --------------------------------------------------------------------- * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale) * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux * * This software is governed by the CeCILL-B license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/ or redistribute the software under the terms of the CeCILL-B * license as circulated by CEA, CNRS and INRIA at the following URL * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html * or in the file LICENSE.txt. * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-B license and that you accept its terms. * ------------------------------------------------------------------------ */ /** * \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" #define bbtkDMessage(key,level,mess) \ bbtkMessage(key,level,"["< ComplexBlackBoxDescriptor::New(\""< ComplexBlackBoxDescriptor(\""<SetAsPrototype(); bbtkDDebugMessage("object",2,"<== ComplexBlackBoxDescriptor(\""< ~ComplexBlackBoxDescriptor()"<Check(recursive); } //========================================================================= //======================================================================= /// Creates an instance of name of the ComplexBlackBox of which this is the descriptor BlackBox::Pointer ComplexBlackBoxDescriptor::NewBlackBox(const std::string& name) { bbtkDDebugMessage("kernel",5, "ComplexBlackBoxDescriptor::NewBlackBox(\"" <bbClone(name); } //======================================================================= /* //======================================================================= /// Release void ComplexBlackBoxDescriptor::Release(bool release_package) { } //======================================================================= */ //======================================================================= /// Adds a black box to the complex box void ComplexBlackBoxDescriptor::Add ( const std::string& type, const std::string& name ) { bbtkDDebugMessage("kernel",5, "ComplexBlackBoxDescriptor::Add(\"" <bbUnsafeGetBlackBox( name ) ) { bbtkError("a black box \""<bbAddBlackBox ( GetFactory()->NewBlackBox(type,name) ); } //======================================================================= //======================================================================= /// Removes a black box from the complex box void ComplexBlackBoxDescriptor::Remove( const std::string& name, bool remove_connections) { mPrototype->bbRemoveBlackBox(name,remove_connections); } //======================================================================= //======================================================================= /// Adds a black box to the execution list void ComplexBlackBoxDescriptor::AddToExecutionList ( const std::string& box) { bbtkDDebugMessage("kernel",5, "ComplexBlackBoxDescriptor::AddToExecutionList(\"" <bbUnsafeGetBlackBox( box ); if ( !b ) { bbtkError("the black box \""<bbAddToExecutionList ( box ); } //======================================================================= /// 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 ) { bbtkDDebugMessage("kernel",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); } //======================================================================= //======================================================================= /// 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) { bbtkDDebugMessage("kernel",5, "ComplexBlackBoxDescriptor::DefineInput(\"" <bbGetBlackBox( box ); if ( !bb ) { bbtkError("the black box \""<bbHasInput(input) ) { bbtkError("the black box \""<bbGetDescriptor()->GetInputDescriptor(input); AddInputDescriptor ( new ComplexBlackBoxInputDescriptor ( typeid(ComplexBlackBoxDescriptor), name, help, d->GetNature(), box, input, d->GetTypeInfo())); } //======================================================================= //======================================================================= /// 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) { bbtkDDebugMessage("kernel",5, "ComplexBlackBoxDescriptor::DefineOutput(\"" <bbGetBlackBox( box ); if ( !bb ) { bbtkError("the black box \""<bbHasOutput(output) ) { bbtkError("the black box \""<bbGetDescriptor()->GetOutputDescriptor(output); AddOutputDescriptor ( new ComplexBlackBoxOutputDescriptor ( typeid(ComplexBlackBoxDescriptor), name, help, d->GetNature(), box, output, d->GetTypeInfo())); } //======================================================================= //======================================================================= 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) { bbtkDDebugMessage("kernel",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); std::vector categories; // Split the category string std::string delimiters = ";,"; Utilities::SplitString(GetCategory(), delimiters,categories); (s) << "

\n"; (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"; } // If B.size (s) << "
Description : " << descr << "
Author(s) : " << author << "
Category(s) : "; std::vector::iterator ci; for (ci=categories.begin(); ci!=categories.end(); ++ci) { s << "" << *ci << " \n"; } s << "
To use it : include "; // s << inc << "  [source]"; // LG TODO : USE PACKAGE BBS PATH s << inc << "  [source]"; s << "
Uses : "; std::set pdeps; ComplexBlackBox::BlackBoxMapType::const_iterator b; for ( b = B.begin(); b != B.end(); ++b ) { BlackBoxDescriptor::Pointer d = b->second->bbGetDescriptor(); if (pdeps.find(d) != pdeps.end()) continue; pdeps.insert(d); Package::Pointer 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"; } // for (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); /*EED 10/11/2009 (s) << "" << "" << "\n"; */ (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); /*EED 10/11/2009 (s) << "" << "" << "\n"; */ (s) << "" << "" << "\n"; } (s) << "
Outputs
 "<
 "<
"<
 "<
 "<
"<
\n"; //------------ // End } //========================================================================= //======================================================================= 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(); if (i->second->GetNature().size()>natlmax) natlmax = i->second->GetNature().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(); if (o->second->GetNature().size()>natlmax) natlmax = o->second->GetNature().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(),' '); std::string nature(i->second->GetNature()); nature += "]"; nature.append(1+natlmax-nature.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(),' '); std::string nature(o->second->GetNature()); nature += "]"; nature.append(1+natlmax-nature.size(),' '); bbtkMessage("help",1, " '"<second->GetDescription()<bbGetBlackBoxMap(); if (B.size()) bbtkMessage("help",1," * Boxes : "<second->bbGetName()<< "' <" << b->second->bbGetDescriptor()->GetPackage()->GetName() <<"::" <second->bbGetTypeName()<<">"<GetObjectRecursiveSize(); return s; } //========================================================================== }