+/*
+ # ---------------------------------------------------------------------
+ #
+ # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+ # pour la SantÈ)
+ # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+ # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+ # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+ #
+ # 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.
+ # ------------------------------------------------------------------------ */
+
+
/*=========================================================================
-
-Program: bbtk
-Module: $RCSfile: bbtkComplexBlackBox.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.
-
+ Program: bbtk
+ Module: $RCSfile: bbtkComplexBlackBox.cxx,v $
+ Language: C++
+ Date: $Date: 2012/11/16 08:49:01 $
+ Version: $Revision: 1.33 $
=========================================================================*/
+
/**
* \file
* \brief class bbtk::ComplexBlackBox : user defined complex black boxes
*/
#include "bbtkComplexBlackBox.h"
-#include "bbtkBlackBoxDescriptor.h"
-#include "bbtkFactory.h"
+#include "bbtkWx.h"
+//#include "bbtkBlackBoxDescriptor.h"
+//#include "bbtkFactory.h"
#include "bbtkConfigurationFile.h"
namespace bbtk
{
+ //==========================================================================
+ /// Creates a new complex black box
+ ComplexBlackBox::Pointer ComplexBlackBox::New(const std::string& name,
+ ComplexBlackBoxDescriptor::Pointer desc)
+ {
+ bbtkDebugMessage("object",1,"##> ComplexBlackBox::New('"<<name<<"','"<<
+ desc->GetTypeName()<<"')" <<bbtkendl);
+ ComplexBlackBox::Pointer p =
+ MakeBlackBoxPointer(new ComplexBlackBox(name,desc));
+ bbtkDebugMessage("object",2,"<## ComplexBlackBox::New('"<<name<<"','"<<
+ desc->GetTypeName()<<"')" <<bbtkendl);
+ return p;
+ }
+ //==========================================================================
//=======================================================================
/// Usefull constructor
ComplexBlackBox::ComplexBlackBox(const std::string &name,
- ComplexBlackBoxDescriptor* desc)
- : BlackBox(name),
- mDescriptor(desc)
+ ComplexBlackBoxDescriptor::Pointer desc)
+ :
+ BlackBox(name),
+ mLockedDescriptor(desc),
+ mDescriptor(desc)
{
- bbtkDebugMessageInc("Core",9,
- "ComplexBlackBox::ComplexBlackBox(\""
- <<name<<"\")"<<std::endl);
+ bbtkBlackBoxDebugMessage("object",3,
+ "##> ComplexBlackBox(\""
+ <<name<<"\")"<<std::endl);
bbAllocateConnectors();
- bbtkDebugDecTab("Core",9);
+ bbtkBlackBoxDebugMessage("object",3,
+ "<## ComplexBlackBox(\""
+ <<name<<"\")"<<std::endl);
}
//=======================================================================
ComplexBlackBox::ComplexBlackBox(ComplexBlackBox& from,
const std::string &name)
: BlackBox(from,name),
+ // The locked descriptor is copied from the unlocked one
+ // to make the box a non-prototype !!
+ mLockedDescriptor(from.mDescriptor),
mDescriptor(from.mDescriptor),
mExecutionList(from.mExecutionList)
{
- bbtkDebugMessageInc("Core",9,
- "ComplexBlackBox::ComplexBlackBox(\""
+ bbtkBlackBoxDebugMessage("object",3,
+ "##> ComplexBlackBox(\""
<<from.bbGetName()<<"\",\""
<<name<<"\")"<<std::endl);
+ bbtkBlackBoxDebugMessage("object",4," * Cloning Black Boxes"<<std::endl);
+
+ // We have to make the shared_ptr on this because it is used
+ // in bbUnsafeAddBlackBox !
+ MakeBlackBoxPointer(this,true);
- bbtkDebugMessageInc("Core",9,"* Cloning Black Boxes"<<std::endl);
BlackBoxMapType::const_iterator i;
for ( i = from.mBlackBoxMap.begin(); i != from.mBlackBoxMap.end(); ++i )
{
- bbtkDebugMessageInc("Core",9,"* Cloning \""<<i->first<<"\""<<std::endl);
- BlackBox* B = i->second->bbClone(i->second->bbGetName());
+ bbtkBlackBoxDebugMessage("object",5," * Cloning \""<<i->first<<"\""<<std::endl);
+ BlackBox::Pointer B = i->second->bbClone(i->second->bbGetName());
bbUnsafeAddBlackBox(B);
-
- bbtkDebugDecTab("Core",9);
}
- bbtkDebugDecTab("Core",9);
- bbtkDebugMessageInc("Core",9,"* Cloning Connections"<<std::endl);
+ bbtkBlackBoxDebugMessage("object",4," * Cloning Connections"<<std::endl);
ConnectionListType::const_iterator j;
for ( j = from.mConnectionList.begin(); j != from.mConnectionList.end(); ++j )
{
- bbtkDebugMessageInc("Core",9,"* Cloning \""<<
- (*j)->GetFullName()<<"\""<<std::endl);
+ bbtkBlackBoxDebugMessage("object",5," * Cloning \""<<
+ (*j)->GetFullName()<<"\""<<std::endl);
+
+ BlackBox::Pointer bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() );
+ BlackBox::Pointer bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() );
- BlackBox* bbfrom = bbGetBlackBox( (*j)->GetBlackBoxFrom()->bbGetName() );
- BlackBox* bbto = bbGetBlackBox( (*j)->GetBlackBoxTo()->bbGetName() );
- Connection* c = /*mDescriptor->GetFactory()->Create*/
+ Connection::Pointer c = mDescriptor.lock()->GetFactory()->
NewConnection( bbfrom,
- (*j)->GetBlackBoxFromOutput(),
+ (*j)->GetOriginalBlackBoxFromOutput(),
bbto,
- (*j)->GetBlackBoxToInput() );
+ (*j)->GetOriginalBlackBoxToInput() );
+ //c->Check();
bbAddConnection(c);
- bbtkDebugDecTab("Core",9);
}
- bbtkDebugDecTab("Core",9);
bbAllocateConnectors();
- bbtkDebugDecTab("Core",9);
+ bbtkBlackBoxDebugMessage("object",3,
+ "<## ComplexBlackBox(\""
+ <<from.bbGetName()<<"\",\""
+ <<name<<"\")"<<std::endl);
}
//=======================================================================
/// Destructor
ComplexBlackBox::~ComplexBlackBox()
{
- bbtkDebugMessageInc("Core",9,
- "ComplexBlackBox::~ComplexBlackBox() ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("object",3,
+ "==> ~ComplexBlackBox()"
+ <<std::endl);
- bbtkDebugMessageInc("Core",9,"* Delete Connections"<<std::endl);
- ConnectionListType::iterator j;
- for ( j = mConnectionList.begin(); j != mConnectionList.end(); ++j )
- {
- bbtkDebugMessageInc("Core",9,"* Delete \""<<
- (*j)->GetFullName()<<"\""<<std::endl);
- delete *j;
- bbtkDebugDecTab("Core",9);
- }
- bbtkDebugDecTab("Core",9);
+ Clear();
+ this->bbDesallocateConnectors();
-
- bbtkDebugMessageInc("Core",9,"* Delete Black Boxes"<<std::endl);
- BlackBoxMapType::iterator i;
- for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
- {
- bbtkDebugMessageInc("Core",9,"* Delete \""<<i->first<<"\""<<std::endl);
- i->second->bbDelete();
- bbtkDebugDecTab("Core",9);
- }
- bbtkDebugDecTab("Core",9);
- // bbtkDebugMessage("Core",9,"EO ComplexBlackBox::~ComplexBlackBox ["
- // <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("object",3,
+ "<== ~ComplexBlackBox()"
+ <<std::endl);
+ }
+ //=======================================================================
+
-
- this->bbDesallocateConnectors();
- bbtkDebugDecTab("Core",9);
+ //=======================================================================
+ /// Clear
+ void ComplexBlackBox::Clear()
+ {
+ bbtkBlackBoxDebugMessage("object",3,
+ "==> ComplexBlackBox::Clear()"
+ <<std::endl);
+
+ bbtkBlackBoxDebugMessage("object",4,
+ " -> Releasing connections"<<std::endl);
+ mConnectionList.clear();
+ bbtkBlackBoxDebugMessage("object",4,
+ " -> Releasing boxes"<<std::endl);
+ mBlackBoxMap.clear();
+
+ bbtkBlackBoxDebugMessage("object",3,
+ "<== ComplexBlackBox::Clear()"
+ <<std::endl);
}
//=======================================================================
/// Allocates the i/o connectors of the black box
void ComplexBlackBox::bbAllocateConnectors()
{
- bbtkDebugMessageInc("Core",8,
- "ComplexBlackBox::bbAllocateConnectors() ["
- <<bbGetFullName()<<"]"
+ bbtkBlackBoxDebugMessage("kernel",8,
+ "==> ComplexBlackBox::bbAllocateConnectors()"
<<std::endl);
-
+
// Input connectors
const BlackBoxDescriptor::InputDescriptorMapType& imap
= bbGetDescriptor()->GetInputDescriptorMap();
BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
for ( i = imap.begin(); i != imap.end(); ++i )
{
- bbtkDebugMessage("Core",8,"* Allocate \""<<i->first<<"\""<<std::endl);
+ bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
// Redirect the connector to the internal box connector
// Cast the BBInputDescriptor into a ComplexBBInputDescriptor
ComplexBlackBoxInputDescriptor* d =
->bbGetInputConnectorMap()[ d->GetInput() ];
bbGetInputConnectorMap()[i->second->GetName()] = c;
-//new BlackBoxInputConnector();
}
// Output connectors
BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
for ( o = omap.begin(); o != omap.end(); ++o )
{
- bbtkDebugMessage("Core",8,"* Allocate \""<<o->first<<"\""<<std::endl);
+ bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
// Redirect the connector to the internal box connector
// Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
ComplexBlackBoxOutputDescriptor* d =
->bbGetOutputConnectorMap()[ d->GetOutput() ];
bbGetOutputConnectorMap()[o->second->GetName()] = c;
- //new BlackBoxOutputConnector();
}
- bbtkDebugDecTab("Core",8);
- }
+ bbtkBlackBoxDebugMessage("kernel",8,
+ "<== ComplexBlackBox::bbAllocateConnectors()"
+ <<std::endl);
+ }
//=========================================================================
/// Desallocates the i/o connectors of the black box
void ComplexBlackBox::bbDesallocateConnectors()
{
- bbtkDebugMessageInc("Core",8,
- "ComplexBlackBox::DesallocateConnectors()"
+ bbtkBlackBoxDebugMessage("kernel",8,
+ "==> ComplexBlackBox::DesallocateConnectors()"
<<std::endl);
// The connectors have not been allocated by the complex box
// BlackBox::bbDesallocateConnectors delete the connectors
bbGetInputConnectorMap().clear();
bbGetOutputConnectorMap().clear();
-
- bbtkDebugDecTab("Core",8);
+
+ bbtkBlackBoxDebugMessage("kernel",8,
+ "<== ComplexBlackBox::DesallocateConnectors()"
+ <<std::endl);
+
}
//=========================================================================
//=======================================================================
- BlackBox* ComplexBlackBox::bbClone(const std::string& name)
+ BlackBox::Pointer ComplexBlackBox::bbClone(const std::string& name)
{
- bbtkDebugMessageInc("Core",9,
- "ComplexBlackBox::bbClone(\""<<name<<"\") ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("kernel",9,
+ "==> ComplexBlackBox::bbClone(\""<<name<<"\")"
+ <<std::endl);
ComplexBlackBox* CBB = new ComplexBlackBox(*this,name);
-
- bbtkDebugDecTab("Core",9);
-
- return CBB;
+ bbtkBlackBoxDebugMessage("kernel",9,
+ "<== ComplexBlackBox::bbClone(\""<<name<<"\")"
+ <<std::endl);
+ return MakeBlackBoxPointer(CBB);
}
//=======================================================================
/// Executes the box so that its outputs are up-to-date on exit
void ComplexBlackBox::bbExecute(bool force)
{
- bbtkDebugMessageInc("Process",1,
- "ComplexBlackBox::bbExecute() ["
- <<bbGetFullName()<<"]"<<std::endl);
-
- wx::BeginBusyCursor();
+ bbtkBlackBoxDebugMessage("process",2,
+ "**> ComplexBlackBox::bbExecute()"
+ <<std::endl);
+
+
+ Wx::BusyCursor wait;
if (mExecutionList.size() != 0)
{
i!=mExecutionList.end();
++i)
{
- bbtkDebugMessage("Process",2," -> Executing '"<<*i<<"'"<<std::endl);
+ bbtkBlackBoxDebugMessage("process",3," -> Executing '"<<*i<<"'"<<std::endl);
mBlackBoxMap[*i]->bbExecute(force);
}
}
else
{
- std::map<std::string, BlackBox*>::iterator i;
+ std::map<std::string, BlackBox::Pointer>::iterator i;
for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i)
{
i->second->bbExecute(force);
}
}
-
- wx::EndBusyCursor();
-
- bbtkDebugDecTab("Process",1);
+ bbtkBlackBoxDebugMessage("process",2,
+ "<** ComplexBlackBox::bbExecute()"
+ <<std::endl);
}
//==================================================================
- //==================================================================
- void ComplexBlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
- {
- bbtkDebugMessage("Process",3,
- "ComplexBlackBox::bbSetModifiedStatus("
- <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
-
- c->GetBlackBox()->bbSetModifiedStatus(c);
-
- bbtkDebugMessage("Process",3,
- "EO ComplexBlackBox::bbSetModifiedStatus("
- <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
- }
- //==================================================================
-
//==================================================================
void ComplexBlackBox::bbAddToExecutionList( const std::string& name )
{
- bbtkDebugMessageInc("Core",9,
+ bbtkBlackBoxDebugMessage("kernel",9,
"ComplexBlackBox::bbAddToExecutionList(\""
- <<name<<"\") ["
- <<bbGetFullName()<<"]"<<std::endl);
-
- mExecutionList.push_back( name );
-
- bbtkDebugDecTab("Core",9);
-
- }
- //==================================================================
-
- //==================================================================
- IOStatus ComplexBlackBox::bbBackwardUpdate(Connection* caller)
- {
- bbtkDebugMessageInc("Process",1,
- "ComplexBlackBox::bbBackwardUpdate("<<caller->GetFullName()<<") ["
- <<bbGetFullName()<<"]"<<std::endl);
-
- IOStatus s = UPTODATE;
- const BlackBoxDescriptor::OutputDescriptorMapType& omap
- = bbGetDescriptor()->GetOutputDescriptorMap();
- BlackBoxDescriptor::OutputDescriptorMapType::const_iterator i
- = omap.find(caller->GetBlackBoxFromOutput());
- if (i!=omap.end())
- {
- // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
- ComplexBlackBoxOutputDescriptor* d =
- (ComplexBlackBoxOutputDescriptor*)i->second;
- // Get the internal box
- BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() );
- // Calls BackwardUpdate on it
- bbtkDebugMessageInc("Process",2,"Internal box connected to output : "<<d->GetTarget()<<std::endl);
- IOStatus s1 = b->bbBackwardUpdate(caller);
- // ??? STATUS OF CBBs ???
- // ??? Here it is only the final status of the boxes connected to the output
- if (s1==MODIFIED) s=MODIFIED;
- bbtkDebugDecTab("Process",2);
- }
- else
- {
- bbtkError("Connection '"<<caller->GetFullName()<<"' does not point to a valid output of the complex box !");
- }
- bbtkDebugDecTab("Process",1);
- return s;
- }
- //==================================================================
-
- /*
- //==================================================================
- void ComplexBlackBox::bbForwardUpdate(Connection* caller)
- {
- bbtkDebugMessageInc("Process",1,
- "ComplexBlackBox::bbForwardUpdate("<<caller->GetFullName()<<") ["
- <<bbGetFullName()<<"]"<<std::endl);
-
- const BlackBoxDescriptor::InputDescriptorMapType& imap
- = bbGetDescriptor()->GetInputDescriptorMap();
- BlackBoxDescriptor::InputDescriptorMapType::const_iterator i
- = imap.find(caller->GetBlackBoxToInput());
- if (i!=imap.end())
- {
- // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
- ComplexBlackBoxInputDescriptor* d =
- (ComplexBlackBoxInputDescriptor*)i->second;
- // Get the internal box
- BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() );
- // Calls ForwardUpdate on it
- bbtkDebugMessage("Process",2,"-> Internal box connected to input : "<<d->GetTarget()<<std::endl);
- b->bbForwardUpdate(caller);
- }
- else
- {
- bbtkError("Connection '"<<caller->GetFullName()<<"' does not point to a valid input of the complex box !");
- }
- bbtkDebugDecTab("Process",1);
+ <<name<<"\")"
+ <<std::endl);
+
+ mExecutionList.push_back( name );
+
+
}
//==================================================================
- */
//==================================================================
Data ComplexBlackBox::bbGetOutput( const std::string &name )
{
- bbtkDebugMessageInc("Data",7,
- "ComplexBlackBox::bbGetOutput(\""<<name<<"\") ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("data",7,
+ "ComplexBlackBox::bbGetOutput(\""<<name<<"\")"
+ <<std::endl);
ComplexBlackBoxOutputDescriptor* d =
(ComplexBlackBoxOutputDescriptor*)
Data p = bbGetBlackBox(d->GetTarget())->bbGetOutput(d->GetOutput());
-
- bbtkDebugDecTab("Data",7);
return p;
}
//==================================================================
/// Gets the input Data of a given name
Data ComplexBlackBox::bbGetInput( const std::string &name )
{
- bbtkDebugMessageInc("Data",7,
- "ComplexBlackBox::bbGetInput(\""<<name<<"\") ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("data",7,
+ "ComplexBlackBox::bbGetInput(\""<<name<<"\")"
+ <<std::endl);
ComplexBlackBoxInputDescriptor* d =
(ComplexBlackBoxInputDescriptor*)
Data p = bbGetBlackBox(d->GetTarget())->bbGetInput(d->GetInput());
- bbtkDebugDecTab("Data",7);
return p;
}
//==================================================================
/// Sets the data of the output called <name>
void ComplexBlackBox::bbSetOutput( const std::string &name, Data data)
{
- bbtkDebugMessageInc("Data",7,
- "ComplexBlackBox::bbSetOutput(\""<<name<<"\",data) ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("data",7,
+ "ComplexBlackBox::bbSetOutput(\""<<name<<"\",data)"
+ <<std::endl);
ComplexBlackBoxOutputDescriptor* d =
(ComplexBlackBoxOutputDescriptor*)
bbGetBlackBox(d->GetTarget())->bbSetOutput(d->GetOutput(),data);
- bbtkDebugDecTab("Data",7);
}
//==================================================================
void ComplexBlackBox::bbSetInput( const std::string &name, Data data,
bool setModified)
{
- bbtkDebugMessageInc("Data",7,
- "ComplexBlackBox::bbSetInput(\""<<name<<"\",data) ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("data",7,
+ "ComplexBlackBox::bbSetInput(\""<<name<<"\",data)"
+ <<std::endl);
ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
bbGetDescriptor()->GetInputDescriptor(name);
bbGetBlackBox(d->GetTarget())->bbSetInput(d->GetInput(),data,setModified);
- bbtkDebugDecTab("Data",7);
}
//==================================================================
void* data,
bool setModified)
{
- bbtkDebugMessageInc("Data",7,
+ bbtkBlackBoxDebugMessage("data",7,
"ComplexBlackBox::bbBruteForceSetInputPointer('"
- <<name<<"',"<<data<<") ["
- <<bbGetFullName()<<"]"<<std::endl);
+ <<name<<"',"<<data<<")"
+ <<std::endl);
ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
bbGetDescriptor()->GetInputDescriptor(name);
data,
setModified);
- bbtkDebugDecTab("Data",7);
}
//==================================================================
+ //=========================================================================
+ /// Connects the input <name> to the connection c
+ void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c)
+ {
+ bbtkBlackBoxDebugMessage("connection",2,
+ "==> ComplexBlackBox::bbConnectInput(\""
+ <<name<<"\","<<c->GetFullName()<<")"
+ <<std::endl);
+
+ ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
+ bbGetDescriptor()->GetInputDescriptor(name);
+
+
+ BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
+
+ bbtkBlackBoxDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
+
+ c->SetBlackBoxTo(t);
+ c->SetBlackBoxToInput(d->GetInput());
+
+ bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
+ t->bbConnectInput(d->GetInput(),c);
+
+ bbtkBlackBoxDebugMessage("connection",2,
+ "<== ComplexBlackBox::bbConnectInput(\""
+ <<name<<"\","<<c->GetFullName()<<")"
+ <<std::endl);
+ }
+ //=========================================================================
+
+
+ //=========================================================================
+ /// Connects the output <name> to the connection c
+ void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c)
+ {
+ bbtkBlackBoxDebugMessage("connection",2,
+ "==> ComplexBlackBox::bbConnectOutput(\""
+ <<name<<"\","<<c->GetFullName()<<")"
+ <<std::endl);
+
+ ComplexBlackBoxOutputDescriptor* d = (ComplexBlackBoxOutputDescriptor*)
+ bbGetDescriptor()->GetOutputDescriptor(name);
+
+ BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
+
+ bbtkBlackBoxDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
+
+ c->SetBlackBoxFrom(t);
+ c->SetBlackBoxFromOutput(d->GetOutput());
+
+ bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
+
+ t->bbConnectOutput(d->GetOutput(),c);
+
+ bbtkBlackBoxDebugMessage("connection",2,
+ "<== ComplexBlackBox::bbConnectOutput(\""
+ <<name<<"\","<<c->GetFullName()<<")"
+ <<std::endl);
+ }
+ //=========================================================================
+
+
//==================================================================
/// Adds the black box to the complex box
- void ComplexBlackBox::bbAddBlackBox( BlackBox* b)
+ void ComplexBlackBox::bbAddBlackBox( BlackBox::Pointer b)
{
- bbtkDebugMessageInc("Core",7,
- "ComplexBlackBox::AddBlackBox(\""<<b->bbGetName()
- <<"\") ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("kernel",7,
+ "ComplexBlackBox::AddBlackBox(\""<<b->bbGetName()
+ <<"\")"
+ <<std::endl);
if ( bbUnsafeGetBlackBox(b->bbGetName()) )
{
bbtkError("a black box called \""<<b->bbGetName()
<<"\" already exists");
}
- b->bbSetParent(this);
+ b->bbSetParent(GetThisPointer<ComplexBlackBox>());
mBlackBoxMap[b->bbGetName()] = b;
- bbtkDebugDecTab("Core",7);
}
//==================================================================
//==================================================================
/// Adds the black box to the complex box (unsafe)
- void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox* b)
+ void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox::Pointer b)
{
- bbtkDebugMessageInc("Core",7,
+ bbtkBlackBoxDebugMessage("kernel",7,
"ComplexBlackBox::UnsafeAddBlackBox(\""<<b->bbGetName()
- <<"\") ["
- <<bbGetFullName()<<"]"<<std::endl);
+ <<"\")"
+ <<std::endl);
- b->bbSetParent(this);
+ b->bbSetParent(GetThisPointer<ComplexBlackBox>());
mBlackBoxMap[b->bbGetName()] = b;
- bbtkDebugDecTab("Core",7);
}
//==================================================================
//==================================================================
/// Removes the black box from the complex box
- void ComplexBlackBox::bbRemoveBlackBox( const std::string& name )
+ void ComplexBlackBox::bbRemoveBlackBox( const std::string& name,
+ bool remove_connections )
{
- bbtkDebugMessageInc("Core",7,
- "ComplexBlackBox::RemoveBlackBox(\""<<name<<"\") ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("kernel",7,
+ "ComplexBlackBox::RemoveBlackBox(\""<<name<<"\")"
+ <<std::endl);
+
+ BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
+ if ( i == mBlackBoxMap.end() )
+ {
+ bbtkError("the black box \""<<name<<"\" does not exist");
+ }
+ BlackBox::WeakPointer p = i->second;
+
+ if (remove_connections)
+ {
+ ConnectionListType::const_iterator j;
+ for ( j = mConnectionList.begin();
+ j != mConnectionList.end(); ++j )
+ {
+ (*j)->Check();
+ }
+ }
+ if (p.use_count()!=1)
+ {
+ bbtkError("the black box \""<<name<<"\" is still connected");
+ }
+
+ mBlackBoxMap.erase(i);
+
- bbtkError("ComplexBlackBox::RemoveBlackBox not implemented");
+ // Unload orphan dl packages
+ Package::UnLoadReleasedDynamicallyLoadedPackages();
- bbtkDebugDecTab("Core",7);
}
//==================================================================
//==================================================================
/// Adds the connection to the complex box
- void ComplexBlackBox::bbAddConnection( Connection* c)
+ void ComplexBlackBox::bbAddConnection( Connection::Pointer c)
{
- bbtkDebugMessageInc("Core",7,
- "ComplexBlackBox::AddConnection(\""<<"..."<<"\") ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("kernel",7,
+ "ComplexBlackBox::AddConnection(\""<<"..."<<"\")"
+ <<std::endl);
mConnectionList.push_back(c);
- bbtkDebugDecTab("Core",7);
}
//==================================================================
// void RemoveConnection( );
//==================================================================
/// Returns the black box with name <name>
- BlackBox* ComplexBlackBox::bbGetBlackBox( const std::string& name )
+ BlackBox::Pointer ComplexBlackBox::bbGetBlackBox( const std::string& name )
{
- bbtkDebugMessageInc("Core",9,
- "ComplexBlackBox::GetBlackBox(\""<<name<<"\") ["
- <<bbGetFullName()<<"]"<<std::endl);
+ bbtkBlackBoxDebugMessage("kernel",9,
+ "ComplexBlackBox::GetBlackBox(\""<<name<<"\")"
+ <<std::endl);
BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
if ( i == mBlackBoxMap.end() )
bbtkError("the black box \""<<name<<"\" does not exist");
}
- bbtkDebugDecTab("Core",9);
return i->second;
}
//==================================================================
//==================================================================
/// Returns the black box with name <name> : does not throw an exception
/// if it does not exist but return a null pointer
- BlackBox* ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name )
+ BlackBox::Pointer ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name )
{
- bbtkDebugMessageInc("Core",9,
- "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\") ["
- <<bbGetFullName()<<"]"
+ bbtkBlackBoxDebugMessage("kernel",9,
+ "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\")"
<<std::endl);
BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
if ( i == mBlackBoxMap.end() )
{
- bbtkDebugDecTab("Core",9);
- return 0;
+ return BlackBox::Pointer();
}
- bbtkDebugDecTab("Core",9);
return i->second;
}
//==================================================================
void ComplexBlackBox::bbPrintBlackBoxes()
{
- bbtkDebugMessageInc("Core",9,
- "ComplexBlackBox::PrintBlackBoxes() ["
- <<bbGetFullName()<<"]"
+ bbtkBlackBoxDebugMessage("kernel",9,
+ "ComplexBlackBox::PrintBlackBoxes()"
<<std::endl);
BlackBoxMapType::iterator i;
for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
{
- bbtkMessage("Help",1,i->second->bbGetFullName()<<std::endl);
+ bbtkMessage("help",1,i->second->bbGetFullName()<<std::endl);
}
- bbtkDebugDecTab("Core",9);
}
//==================================================================
//=========================================================================
- BlackBox *ComplexBlackBox::bbFindBlackBox(const std::string &blackboxname)
+ BlackBox::Pointer ComplexBlackBox::bbFindBlackBox(const std::string &blackboxname)
{
- BlackBox *blackbox=NULL;
+ BlackBox::Pointer blackbox;
std::string subname="";
std::string restname="";
std::string delimiters(">");
restname = blackboxname.substr(lastPos+pos - lastPos+1, 999);
if (restname==subname)
- {
- restname="";
- }
+ {
+ restname="";
+ }
BlackBoxMapType::iterator i = mBlackBoxMap.find(subname);
- if ( i == mBlackBoxMap.end() )
- {
- blackbox = NULL;
- } else {
- blackbox = i->second;
- if (restname!="")
- {
- blackbox = blackbox->bbFindBlackBox(restname);
- }
+ if ( i != mBlackBoxMap.end() )
+ {
+ blackbox = i->second;
+ if (restname!="")
+ {
+ blackbox = blackbox->bbFindBlackBox(restname);
+ }
}
return blackbox;
}
const std::string& output_dir,
bool relative_link )
{
-
std::string directory(output_dir);
if (output_dir.length() == 0)
- {
- // Don't pollute the file store with "doc_tmp" directories ...
- std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_doc_tmp();
- directory = default_doc_dir + "/" + "doc_tmp";
- }
+ {
+ // Don't pollute the file store with "temp_dir" directories ...
+ std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
+ directory = default_temp_dir + "/" + "temp_dir";
+ }
std::string simplefilename (this->bbGetTypeName()+"_"+this->bbGetName());
std::string simplefilename_png (simplefilename+".png");
std::string filename_dot2 ("\"" + filename_dot + "\"");
- std::string command1 ("dot -T png -o "
- + filename_png2 + " " + filename_dot2);
- std::string command1a("dot -T cmap -o "
- + filename_cmap2 + " " + filename_dot2);
+#ifdef WIN32
+ std::string currentexecpath("\"\"" + crea::System::GetDllAppPath("bbtk") +"\\dot_embedded\\dot\"");
+ std::string command1 (currentexecpath + " -Tpng -o " + filename_png2 + " " + filename_dot2 + "\"");
+ std::string command1a(currentexecpath + " -T cmap -o " + filename_cmap2 + " " + filename_dot2 + "\"");
+#else
+ #ifdef APPLE
+ std::string command1 ("dot -Tpng:quartz -o " + filename_png2 + " " + filename_dot2 );
+ std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
+ #else
+ std::string command1 ("dot -Tpng:cairo -o " + filename_png2 + " " + filename_dot2 );
+ std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
+ #endif
+#endif
+
+
+
// 1. Generating .dot file
FILE *ff;
fprintf(ff,"rankdir=LR%s\n",";");
fprintf(ff,"node [shape=record]%s\n",";");
- this->bbWriteDotFileBlackBox(ff,this,detail,level,
+ this->bbWriteDotFileBlackBox(ff,
+ GetThisPointer<ComplexBlackBox>(),
+ detail,level,
instanceOrtype,
relative_link );
fprintf(ff,"}\n");
fclose(ff);
+ std::cout<<"JCP bbtkComplexBlackBox.cxx execute1="<<command1<<std::endl;
// 2. Executing .dot file -> png
system( command1.c_str() );
// 3. Executing .dot file -> cmap
+ std::cout<<"JCP bbtkComplexBlackBox.cxx execute2="<<command1a<<std::endl;
system( command1a.c_str() );
// 4. HTML code insertion
FILE *ff2;
char c;
ff2=fopen(filename_cmap.c_str(),"r");
- while (!feof(ff2))
- {
- c=fgetc(ff2);
- if (c!=-1)
- {
- (s) << c;
- }
- }
+ if (ff2!=NULL){
+ while (!feof(ff2))
+ {
+ c=fgetc(ff2);
+ if (c!=-1)
+ {
+ (s) << c;
+ } // if
+ } // while
+ } // if ff2
(s) << "</map>\n\n";
// End
//=========================================================================
/// Write Graphviz-dot description in file
void ComplexBlackBox::bbWriteDotFileBlackBox(FILE *ff,
- BlackBox *parentblackbox,
+ BlackBox::Pointer parentblackbox,
int detail, int level,
bool instanceOrtype,
bool relative_link )
{
std::string tmp1;
std::string valueStr("");
- Package *package = this->bbGetDescriptor()->GetPackage();
+ Package::Pointer package = this->bbGetDescriptor()->GetPackage();
if (package!=NULL)
- {
- if (relative_link)
- tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL();
- else
- tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL();
- }
+ {
+ if (relative_link)
+ tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL();
+ else
+ tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL();
+ }
else
- {
- tmp1 = "Caspitas";
- }
+ {
+ tmp1 = "Caspitas";
+ }
std::string tmp2=bbGetTypeName();
std::string url(tmp1 + "#" + tmp2 );
fprintf( ff , "subgraph cluster_%s_%p {\n",bbGetName().c_str(),this);
if (!( (bbGetTypeName()=="workspace") && (bbGetName()=="workspacePrototype")) )
- {
- fprintf( ff , " URL = \"%s\" %s",url.c_str(),";");
- }
+ {
+ fprintf( ff , " URL = \"%s\" %s",url.c_str(),";");
+ }
std::string boxname="["+bbGetTypeName()+"]";
- if (this!=parentblackbox)
- {
- if (detail==0)
- {
- boxname=bbGetName();
- } else {
- boxname = bbGetName();
- boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
- }
+ if (GetThisPointer<ComplexBlackBox>()!=parentblackbox)
+ {
+ if (detail==0)
+ {
+ boxname=bbGetName();
+ }
+ else
+ {
+ boxname = bbGetName();
+ boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
+ }
- }
+ }
fprintf( ff , " label = \"%s\"%s\n", boxname.c_str() ,";");
{
if (level>-1)
{
- j->second->bbWriteDotFileBlackBox(ff,parentblackbox,detail,
+ j->second->bbWriteDotFileBlackBox(ff,
+ parentblackbox,
+ detail,
level-1,
instanceOrtype,
relative_link);
fprintf(ff,":%s",cbbid->GetName().c_str() );
}
fprintf(ff,"->" );
- BlackBox *bb = bbGetBlackBox( cbbid->GetTarget() );
+ BlackBox::Pointer bb = bbGetBlackBox( cbbid->GetTarget() );
bb->bbWriteDotInputOutputName(ff,true,detail,level);
if (detail==1)
{
{
ComplexBlackBoxOutputDescriptor *cbbod = (ComplexBlackBoxOutputDescriptor*)yy->second;
fprintf(ff," ");
- BlackBox *bb = bbGetBlackBox( cbbod->GetTarget() );
+ BlackBox::Pointer bb = bbGetBlackBox( cbbod->GetTarget() );
bb->bbWriteDotInputOutputName(ff,false,detail,level);
if (detail==1)
{
// Relation from the out side of this ComplexBlackBox with its Inputs
- if (this!=parentblackbox) {
+ if (GetThisPointer<ComplexBlackBox>()!=parentblackbox) {
for ( ii = bbGetInputConnectorMap().begin();
ii != bbGetInputConnectorMap().end(); ++ii )
{
{
Connection* con = ii->second->GetConnection();
if (con!=NULL){
- BlackBox *a=con->GetBlackBoxFrom();
- BlackBox *b=con->GetBlackBoxTo();
+ BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
+ BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
fprintf(ff," ");
a->bbWriteDotInputOutputName(ff,false,detail,level);
if (detail==1)
{
- fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str());
+ fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
}
fprintf(ff,"->");
b->bbWriteDotInputOutputName(ff,true,detail,level);
if (detail==1)
{
- fprintf(ff,":%s",con->GetBlackBoxToInput().c_str());
+ fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
}
fprintf(ff,"%s\n",";");
} // if con
} // if second
} // for
} // if parentblackbox
-
}
//=========================================================================
+
+
- /*
+ /*
//=======================================================================
/// Generates the list of the packages of which its depends
}
//=======================================================================
*/
+
+ //=======================================================================
+ void ComplexBlackBox::Check(bool recursive)
+ {
+ bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
+ <<" ["<<bbGetFullName()<<"]"<<std::endl);
+
+ BlackBoxMapType::const_iterator i;
+ for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
+ {
+ i->second->Check(recursive);
+ }
+ ConnectionListType::const_iterator j;
+ for ( j = mConnectionList.begin();
+ j != mConnectionList.end(); ++j )
+ {
+ (*j)->Check();
+ }
+ bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
+ <<" ["<<bbGetFullName()<<"] ... OK"<<std::endl);
+
+ }
+ //=======================================================================
+
+ //=========================================================================
+ /// Returns the name with the name of the parent prepended if any
+ std::string ComplexBlackBox::bbGetNameWithParent() const
+ {
+ if (!IsAPrototype()) return BlackBox::bbGetNameWithParent();
+ if (bbGetDescriptor())
+ {
+ return bbGetDescriptor()->GetFullTypeName() + ":" + bbGetName();
+ }
+ else
+ {
+ return std::string(":") + bbGetName();
+ }
+ }
+ //=========================================================================
+
+ //==========================================================================
+ std::string ComplexBlackBox::GetObjectName() const
+ {
+ return std::string("ComplexBlackBox '")+bbGetNameWithParent()
+ +std::string("'");
+ }
+ //==========================================================================
+
+ //==========================================================================
+ std::string ComplexBlackBox::GetObjectInfo() const
+ {
+ std::stringstream i;
+ i << " - "<<mBlackBoxMap.size() << " boxes / "
+ <<mConnectionList.size() << " connections" << std::endl;
+ return i.str();
+ }
+ //==========================================================================
+
+ //==========================================================================
+ size_t ComplexBlackBox::GetObjectSize() const
+ {
+ size_t s = Superclass::GetObjectSize();
+ s += ComplexBlackBox::GetObjectInternalSize();
+ return s;
+ }
+ //==========================================================================
+ //==========================================================================
+ size_t ComplexBlackBox::GetObjectInternalSize() const
+ {
+ size_t s = sizeof(ComplexBlackBox);
+ return s;
+ }
+ //==========================================================================
+ //==========================================================================
+ size_t ComplexBlackBox::GetObjectRecursiveSize() const
+ {
+ size_t s = Superclass::GetObjectRecursiveSize();
+ s += ComplexBlackBox::GetObjectInternalSize();
+ BlackBoxMapType::const_iterator i;
+ for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
+ {
+ s += i->second->GetObjectRecursiveSize();
+ }
+ ConnectionListType::const_iterator j;
+ for ( j = mConnectionList.begin();
+ j != mConnectionList.end(); ++j )
+ {
+ s += (*j)->GetObjectRecursiveSize();
+ }
+ return s;
+ }
+ //==========================================================================
+
}