From c03be5662c1ea498e612cbaa9f9b7a9988a65765 Mon Sep 17 00:00:00 2001 From: guigues Date: Fri, 7 Mar 2008 08:40:14 +0000 Subject: [PATCH] Global factory in course of removal... does not compile but have to commit to continue on laptop ! Will be fixed very quick ! --- kernel/src/bbtkBlackBox.cxx | 98 ++++++---- kernel/src/bbtkBlackBoxDescriptor.h | 6 +- kernel/src/bbtkExecuter.cxx | 179 +++++++++--------- kernel/src/bbtkExecuter.h | 44 +++-- kernel/src/bbtkFactory.cxx | 152 +++++++-------- kernel/src/bbtkFactory.h | 24 ++- kernel/src/bbtkInterpreter.cxx | 47 ++--- kernel/src/bbtkInterpreter.h | 38 +++- kernel/src/bbtkPackage.cxx | 15 +- kernel/src/bbtkPackage.h | 23 ++- kernel/src/bbtkVirtualExec.h | 30 ++- kernel/src/bbtkWxConsole.cxx | 5 +- kernel/src/bbtkWxConsole.h | 16 +- .../appli/ExampleBasicImageApplication.bbs | 48 +++++ .../bbs/boxes/bbBasicImageApplication.bbs | 115 +++++++++++ 15 files changed, 562 insertions(+), 278 deletions(-) create mode 100644 packages/wxvtk/bbs/appli/ExampleBasicImageApplication.bbs create mode 100644 packages/wxvtk/bbs/boxes/bbBasicImageApplication.bbs diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 7955ccf..94610b0 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkBlackBox.cxx,v $ Language: C++ -Date: $Date: 2008/02/20 16:05:38 $ -Version: $Revision: 1.5 $ +Date: $Date: 2008/03/07 08:40:14 $ +Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or @@ -649,28 +649,40 @@ namespace bbtk // Looks for the adaptor if (bbGetOutputType(output).name() != typeid(std::string).name() ) { - BlackBox* a = 0; - try + // Look for factory + Package* p = bbGetDescriptor()->GetPackage(); + if ((p != 0) && ( ! p->GetFactorySet().empty() ) ) { - a = NewAdaptor( - bbGetOutputType(output), - typeid(std::string), - ""); - } catch (bbtk::Exception e) + Factory* f = *p->GetFactorySet().begin(); + BlackBox* a = 0; + try + { + a = f->NewAdaptor( + bbGetOutputType(output), + typeid(std::string), + ""); + } catch (bbtk::Exception e) + { + } + if (a!=NULL){ + // bbUpdate(); + a->bbSetInput("In",bbGetOutput(output)); + a->bbExecute(); + v = a->bbGetOutput("Out").unsafe_get() ; + } else { + v="? (no adaptor found)"; + } + } + else { + v="? (no factory found)"; } - if (a!=NULL){ - // bbUpdate(); - a->bbSetInput("In",bbGetOutput(output)); - a->bbExecute(); - v = a->bbGetOutput("Out").unsafe_get() ; - } else { - v="? (no adaptor found)"; - } - } else { - // bbUpdate(); - v = bbGetOutput(output).unsafe_get() ; - } + } + else + { + // bbUpdate(); + v = bbGetOutput(output).unsafe_get() ; + } return v; } //========================================================================= @@ -682,28 +694,38 @@ namespace bbtk // Looks for the adaptor if (bbGetInputType(input) != typeid(std::string)) { - BlackBox* a = 0; - try + // Look for factory + Package* p = bbGetDescriptor()->GetPackage(); + if ((p != 0) && ( ! p->GetFactorySet().empty() ) ) { - a = NewAdaptor( - bbGetInputType(input), - typeid(std::string), - ""); - }catch (bbtk::Exception e) - { - } - if (a!=NULL) - { - // bbUpdate(); - a->bbSetInput("In",bbGetInput(input)); - a->bbExecute(); - v = a->bbGetOutput("Out").unsafe_get() ; + Factory* f = *p->GetFactorySet().begin(); + BlackBox* a = 0; + try + { + a = f->NewAdaptor( + bbGetInputType(input), + typeid(std::string), + ""); + }catch (bbtk::Exception e) + { + } + if (a!=NULL) + { + // bbUpdate(); + a->bbSetInput("In",bbGetInput(input)); + a->bbExecute(); + v = a->bbGetOutput("Out").unsafe_get() ; + } + else + { + v="? (no adaptor found)"; + } } else { - v="? (no adaptor found)"; + v="? (no factory found)"; } - } + } else { v = bbGetInput(input).unsafe_get() ; diff --git a/kernel/src/bbtkBlackBoxDescriptor.h b/kernel/src/bbtkBlackBoxDescriptor.h index 1d0ee5d..6443d50 100644 --- a/kernel/src/bbtkBlackBoxDescriptor.h +++ b/kernel/src/bbtkBlackBoxDescriptor.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkBlackBoxDescriptor.h,v $ Language: C++ - Date: $Date: 2008/02/06 14:14:22 $ - Version: $Revision: 1.5 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -83,7 +83,7 @@ namespace bbtk /// Returns the Package to which the box belongs Package* GetPackage() { return mPackage; } - /// Returns the Package to which the box belongs + /// Returns the Package to which the box belongs (const pointer) const Package* GetPackage() const { return mPackage; } /// Returns the kind of box diff --git a/kernel/src/bbtkExecuter.cxx b/kernel/src/bbtkExecuter.cxx index 7d24b70..241573a 100644 --- a/kernel/src/bbtkExecuter.cxx +++ b/kernel/src/bbtkExecuter.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkExecuter.cxx,v $ $ Language: C++ - Date: $Date: 2008/02/14 20:57:27 $ - Version: $Revision: 1.12 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.13 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -40,14 +40,16 @@ namespace bbtk * */ Executer::Executer() - : mPackage(0), - mRoot(0), - mNoExecMode(false), - mDialogMode(NoDialog) + : + mFactory(0), + mRootPackage(0), + mRootCBB(0), + mNoExecMode(false), + mDialogMode(NoDialog) { - //VirtualExec(); - bbtkDebugMessageInc("Kernel",9,"Executer::Executer()" <SetExecuter(this); Reset(); bbtkDebugDecTab("Kernel",9); } @@ -57,17 +59,19 @@ namespace bbtk */ Executer::~Executer() { -std::cout << "====================================================== delete Executer\n"; + //std::cout << "===================================== delete Executer\n"; bbtkDebugMessageInc("Kernel",9,"Executer::~Executer()" <UnRegisterBlackBox("workspace"); - delete mRoot; + mRootPackage->UnRegisterBlackBox("workspace"); + delete mRootCBB; } - if (mPackage) + if (mRootPackage) { - GetGlobalFactory()->UnLoadPackage("user"); + GetFactory()->UnLoadPackage("user"); } + delete mFactory; + bbtkDebugDecTab("Kernel",9); } @@ -85,38 +89,41 @@ std::cout << "====================================================== delete Exec // all user defined CBB otherwise any instance // of a user CBB that is in the 'workspace' would try to // access a user CBB descriptor which has been previously freed - if (mRoot) + if (mRootCBB) { - mPackage->UnRegisterBlackBox(mRoot->GetTypeName()); - delete mRoot; + mRootPackage->UnRegisterBlackBox(mRootCBB->GetTypeName()); + delete mRootCBB; } - if (mPackage) + if (mRootPackage) { - GetGlobalFactory()->UnLoadPackage("user"); + GetFactory()->UnLoadPackage("user"); } - GetGlobalFactory()->Reset(); + GetFactory()->Reset(); + // Create user package - mPackage = new Package("user","internal to bbi", + mRootPackage = new Package("user","internal to bbi", "User defined black boxes", "", BBTK_STRINGIFY_SYMBOL(BBTK_VERSION)); // Create user workspace - mRoot = new ComplexBlackBoxDescriptor("workspace"); //,f); - mRoot->AddToAuthor("bbi (internal)"); - mRoot->AddToDescription("User's workspace"); - mOpenDefinition.push_back(CBBDefinition(mRoot,"user")); + mRootCBB = new ComplexBlackBoxDescriptor("workspace"); //,f); + mRootCBB->AddToAuthor("bbi (internal)"); + mRootCBB->AddToDescription("User's workspace"); + mOpenDefinition.push_back(CBBDefinition(mRootCBB,"user")); // Register it into the user package - mPackage->RegisterBlackBox(mRoot); + mRootPackage->RegisterBlackBox(mRootCBB); // Insert the user package in the factory - InsertPackage(mPackage); - mOpenPackage.push_back(mPackage); + GetFactory()->InsertPackage(mRootPackage); + // And in the list of open packages + mOpenPackage.push_back(mRootPackage); + bbtkDebugDecTab("Kernel",9); } /// changes the workspace name void Executer::SetWorkspaceName( const std::string& n ) { - mPackage->ChangeBlackBoxName( mRoot->GetTypeName(), n ); + mRootPackage->ChangeBlackBoxName( mRootCBB->GetTypeName(), n ); } void Executer::BeginPackage (const std::string &name) @@ -126,7 +133,7 @@ std::cout << "====================================================== delete Exec Package* p; try { - p = GetGlobalFactory()->GetPackage(name); + p = GetFactory()->GetPackage(name); } catch (Exception e) { @@ -135,7 +142,7 @@ std::cout << "====================================================== delete Exec "", "", BBTK_STRINGIFY_SYMBOL(BBTK_VERSION)); - InsertPackage(p); + GetFactory()->InsertPackage(p); } mOpenPackage.push_back(p); } @@ -176,30 +183,30 @@ std::cout << "====================================================== delete Exec Package* p; std::string pname(mOpenDefinition.back().package); if (pname.size()>0) - { - try { - p = GetGlobalFactory()->GetPackage(pname); + try + { + p = GetFactory()->GetPackage(pname); + } + catch (Exception e) + { + p = new Package(pname, + "", + "", + "", + BBTK_STRINGIFY_SYMBOL(BBTK_VERSION)); + GetFactory()->InsertPackage(p); + } } - catch (Exception e) + else { - p = new Package(pname, - "", - "", - "", - BBTK_STRINGIFY_SYMBOL(BBTK_VERSION)); - InsertPackage(p); + p = mOpenPackage.back(); } - } - else - { - p = mOpenPackage.back(); - } p->RegisterBlackBox(Current()); - + mOpenDefinition.pop_back(); } - + void Executer::Create ( const std::string& nodeType, const std::string& nodeName) @@ -231,7 +238,7 @@ std::cout << "====================================================== delete Exec void Executer::Update (const std::string &nodeName) // would 'Execute' be more meaningfull ? { // if in root - if (Current()==mRoot) + if (Current()==mRootCBB) { if (!mNoExecMode) { @@ -253,7 +260,7 @@ std::cout << "====================================================== delete Exec const std::string& help) { // If the input is defined in the Root box - if (Current()==mRoot) + if (Current()==mRootCBB) { // If the dialog mode is set to NoDialog // and the user passed the name in the Inputs map @@ -323,15 +330,15 @@ std::cout << "====================================================== delete Exec if ( b->bbGetInputType(input) != typeid(std::string) ) { BlackBox* a = - NewAdaptor(typeid(std::string), - b->bbGetInputType(input), - "tmp"); + GetFactory()->NewAdaptor(typeid(std::string), + b->bbGetInputType(input), + "tmp"); if (!a) - { - bbtkError("No <"<< - TypeName(b->bbGetInputType(input)) - <<"> to found"); - } + { + bbtkError("No <"<< + TypeName(b->bbGetInputType(input)) + <<"> to found"); + } std::string v(value); a->bbSetInput("In",v); a->bbExecute(); @@ -355,55 +362,55 @@ std::cout << "====================================================== delete Exec // Looks for the adaptor if (b->bbGetOutputType(output) != typeid(std::string)) { - BlackBox* a = - NewAdaptor( - b->bbGetOutputType(output), - typeid(std::string), - "tmp"); - if (!a) - { - bbtkError("No <"<< - TypeName(b->bbGetOutputType(output)) - <<"> to found"); - } + BlackBox* a = + GetFactory()->NewAdaptor( + b->bbGetOutputType(output), + typeid(std::string), + "tmp"); + if (!a) + { + bbtkError("No <"<< + TypeName(b->bbGetOutputType(output)) + <<"> to found"); + } b->bbExecute(); - + a->bbSetInput("In",b->bbGetOutput(output)); a->bbExecute(); std::string r = a->bbGetOutput("Out").unsafe_get(); - //std::string v = *((std::string*)a->bbGetOutput("Out")) ; - // std::cout << a->bbGetOutput("Out").unsafe_get() - // << std::endl; - //std::string v(value); - //b->bbSetInput(input,a->bbGetOutput("Out")); + //std::string v = *((std::string*)a->bbGetOutput("Out")) ; + // std::cout << a->bbGetOutput("Out").unsafe_get() + // << std::endl; + //std::string v(value); + //b->bbSetInput(input,a->bbGetOutput("Out")); a->bbDelete(); return r; } else { - b->bbExecute(); - return b->bbGetOutput(output).unsafe_get(); - // std::string v = *((std::string*)b->bbGetOutput(output)) ; - // std::cout << b->bbGetOutput("Out").unsafe_get() - // << std::endl; - // b->bbSetInput(input,&v); + b->bbExecute(); + return b->bbGetOutput(output).unsafe_get(); + // std::string v = *((std::string*)b->bbGetOutput(output)) ; + // std::cout << b->bbGetOutput("Out").unsafe_get() + // << std::endl; + // b->bbSetInput(input,&v); } } void Executer::Author(const std::string &authorName) { - Current()->AddToAuthor(authorName,Current()==mRoot); + Current()->AddToAuthor(authorName,Current()==mRootCBB); } void Executer::Category(const std::string &category) { - Current()->AddToCategory(category,Current()==mRoot); + Current()->AddToCategory(category,Current()==mRootCBB); } void Executer::Description(const std::string &d) { - Current()->AddToDescription(d,Current()==mRoot); + Current()->AddToDescription(d,Current()==mRootCBB); } @@ -457,11 +464,11 @@ std::cout << "====================================================== delete Exec Package* p; try { - p = GetGlobalFactory()->GetPackage(nameblackbox); + p = GetFactory()->GetPackage(nameblackbox); } catch (Exception e) { - p = mPackage; + p = mRootPackage; } // Generating documentation-help of workspace p->SetDocURL(filename_rootHtml); diff --git a/kernel/src/bbtkExecuter.h b/kernel/src/bbtkExecuter.h index ef109b3..b77a3c9 100644 --- a/kernel/src/bbtkExecuter.h +++ b/kernel/src/bbtkExecuter.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkExecuter.h,v $ $ Language: C++ - Date: $Date: 2008/02/14 20:26:54 $ - Version: $Revision: 1.9 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -38,6 +38,9 @@ namespace bbtk { + class Interpreter; + + class /*BBTK_EXPORT*/ Executer : public VirtualExec { @@ -45,13 +48,16 @@ namespace bbtk /// Constructor Executer(); - - /// - // void SetFactory(Factory* f); - /// Destructor ~Executer(); + + /// Gets the factory used by the executer + Factory* GetFactory() { return mFactory; } + /// Gets the factory used by the executer (const) + const Factory* GetFactory() const { return mFactory; } + + /// Sets the inputs of the workspace : void SetInputs(const std::map& m) { mInputs = m; } @@ -135,7 +141,7 @@ namespace bbtk /// prints the list off the boxes of the current box void PrintBoxes(); - /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path + /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path std::string ShowGraph(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr, @@ -144,7 +150,7 @@ namespace bbtk const std::string &custom_title, bool system_display = true); - /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path + /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true); /// Description of the actual pipeline @@ -170,14 +176,19 @@ namespace bbtk // ATTRIBUTES /// The factory used - // Factory* mFactory; - - /// The Root Package - Package* mPackage; + Factory* mFactory; - /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block + + /// The Root Package + /// Contains the root ComplexBlabkBox + /// In which ComplexBlackBoxes are put by default + /// Its name in bbi is 'user' + Package* mRootPackage; + + /// The root ComplexBlackBox + /// in which operations are done when outside a define/endefine block /// Its name in bbi is 'workspace' - ComplexBlackBoxDescriptor* mRoot; + ComplexBlackBoxDescriptor* mRootCBB; /// Struct that stores info on user defined complex black boxes struct CBBDefinition @@ -190,16 +201,13 @@ namespace bbtk /// The stack of current working ComplexBlackBox /// (is a stack for nested definitions) - /// only contains the root when outside a define/endefine block + /// only contains the root cbb when outside a define/endefine block std::deque mOpenDefinition; /// The stack of current working package /// (is a stack for nested definitions) std::deque mOpenPackage; - /// flag which is true when we are inside a Define/EndDefine block - // bool mDefineFlag; - /// The input values of the Root ComplexBlackBox std::map mInputs; diff --git a/kernel/src/bbtkFactory.cxx b/kernel/src/bbtkFactory.cxx index 74d515d..5e9c395 100644 --- a/kernel/src/bbtkFactory.cxx +++ b/kernel/src/bbtkFactory.cxx @@ -4,8 +4,8 @@ Program: bbtk Module: $RCSfile: bbtkFactory.cxx,v $ Language: C++ -Date: $Date: 2008/03/04 08:09:04 $ -Version: $Revision: 1.26 $ +Date: $Date: 2008/03/07 08:40:14 $ +Version: $Revision: 1.27 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de @@ -37,20 +37,6 @@ PURPOSE. See the above copyright notices for more information. #include // std::toupper -// was in gdcm ... -/* -#ifdef _MSC_VER -# define getcwd _getcwd -#endif - -#if defined(_MSC_VER) || defined(__BORLANDC__) -# include -#else -# include -#endif - -*/ - namespace bbtk { @@ -61,6 +47,7 @@ namespace bbtk //=================================================================== /// Default ctor Factory::Factory() + : mExecuter(0) { bbtkDebugMessage("Kernel",7,"Factory::Factory()"<GetBBTKVersion() != bbtk::GetVersion() ) { @@ -215,6 +200,9 @@ namespace bbtk << " whereas application build with version " << bbtk::GetVersion()); } + + pack.mPackage->AddFactory(this); + mPackageMap[pkgname] = pack; std::string separator = ConfigurationFile::GetInstance().Get_file_separator (); @@ -444,71 +432,85 @@ namespace bbtk //=================================================================== /// \brief Close the package referenced by the iterator - /// - /// If it is a dynamically loaded package - /// - Loads and calls the function "DeletePackage" of the dynamic library (responsible for package desallocation) - /// - Closes the dynamic library - /// - Erases the package entry in the packages map - /// - /// Else simply erases the package entry in the packages map - void Factory::ClosePackage(PackageMapType::iterator& i) + /// + /// First removes the factory from the set of factories which use the package + /// If the set is empty then : + /// If it is a dynamically loaded package : + /// - Loads and calls the function "DeletePackage" of the dynamic library (responsible for package desallocation) + /// - Closes the dynamic library + /// Else : + /// - deletes the package normally + /// + /// Finally erases the package entry in the packages map + void Factory::ClosePackage(PackageMapType::iterator& i) { bbtkDebugMessageInc("Kernel",7,"Factory::ClosePackage(\"" <second.mPackage->GetName() <<"\")"<second.mDynamicLibraryHandler) - { - - // If it is a dynamically loaded package - // Loads the Package delete function - - std::string delfname(i->second.mPackage->GetName()); - delfname += "DeletePackage"; + + // Removes this from the set of factories which use the package + i->second.mPackage->RemoveFactory(this); + + // If no more factory which use it + if (i->second.mPackage->GetFactorySet().empty()) + { + // If it is a dynamically loaded package + if (i->second.mDynamicLibraryHandler) + { + + + // Loads the Package delete function + + std::string delfname(i->second.mPackage->GetName()); + delfname += "DeletePackage"; #if defined(__GNUC__) - void *delf = dlsym(i->second.mDynamicLibraryHandler, delfname.c_str()); - if (!delf) - { - bbtkError("could not close package \"" - <second.mPackage->GetName() - <<"\" :"<second.mDynamicLibraryHandler, delfname.c_str()); + if (!delf) + { + bbtkError("could not close package \"" + <second.mPackage->GetName() + <<"\" :"<second.mDynamicLibraryHandler, - delfname.c_str()); - if (!delf) - { - bbtkError("could not close package \"" - <second.mPackage->GetName() - <<"\" : "<second.mDynamicLibraryHandler, + delfname.c_str()); + if (!delf) + { + bbtkError("could not close package \"" + <second.mPackage->GetName() + <<"\" : "<second.mDynamicLibraryHandler); + dlclose(i->second.mDynamicLibraryHandler); #elif defined(_WIN32) - - FreeLibrary(i->second.mDynamicLibraryHandler); + + FreeLibrary(i->second.mDynamicLibraryHandler); #endif - } - else - { - // If it is a manually inserted package - delete i->second.mPackage; - } + } - // remove the entry in the map - mPackageMap.erase(i); - bbtkDebugDecTab("Kernel",7); - } - //=================================================================== + else + { + // If it is a manually inserted package : delete it normally + delete i->second.mPackage; + } + } + + // in any cases remove the entry in the map + mPackageMap.erase(i); + bbtkDebugDecTab("Kernel",7); + } + //=================================================================== + //=================================================================== @@ -614,12 +616,12 @@ namespace bbtk bbtkDebugMessageInc("Kernel",9,"Factory::InsertPackage(\""<< p->GetName()<<"\")"<AddFactory(this); PackageInfoType pack; pack.mDynamicLibraryHandler = 0; - pack.mPackage = p; - mPackageMap[p->GetName()] = pack; + bbtkDebugDecTab("Kernel",9); } //=================================================================== @@ -639,12 +641,12 @@ namespace bbtk if (i!=mPackageMap.end()) { - ClosePackage(i); + ClosePackage(i); } else { - bbtkError("Factory::RemovePackage(\""<< - p->GetName()<<"\") : package absent from factory"); + bbtkError("Factory::RemovePackage(\""<< + p->GetName()<<"\") : package absent from factory"); } bbtkDebugDecTab("Kernel",9); diff --git a/kernel/src/bbtkFactory.h b/kernel/src/bbtkFactory.h index 35c04e6..75acb76 100644 --- a/kernel/src/bbtkFactory.h +++ b/kernel/src/bbtkFactory.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkFactory.h,v $ Language: C++ - Date: $Date: 2008/03/03 14:55:55 $ - Version: $Revision: 1.9 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or @@ -35,6 +35,9 @@ namespace bbtk { + + class Executer; + class BBTK_EXPORT Factory { @@ -42,7 +45,7 @@ namespace bbtk Factory(); ~Factory(); - + void LoadPackage( const std::string& name ); void UnLoadPackage( const std::string& name ); void PrintPackages(bool details = true, bool adaptors = false) const; @@ -82,6 +85,14 @@ namespace bbtk IndexEntryType; void CreateHtmlIndex(IndexEntryType type, const std::string& filename); + /// Sets the executer who created the factory (if any) + void SetExecuter(Executer *e) { mExecuter = e; } + /// Gets the executer who created the factory (if any) + Executer* GetExecuter() { return mExecuter; } + /// Gets the executer who created the factory (if any) - const + const Executer* GetExecuter() const { return mExecuter; } + + private: bool DoLoadPackage(std::string libname, @@ -106,6 +117,9 @@ namespace bbtk /// The map of packages PackageMapType mPackageMap; + /// The executer which created the factory (if any) + Executer* mExecuter; + void CloseAllPackages(); void ClosePackage(PackageMapType::iterator& i); @@ -113,6 +127,8 @@ namespace bbtk // class Factory + + /* /// SYSTEM METHOD : Global method returning the global factory object pointer inline Factory*& GlobalFactoryPointer() { @@ -218,7 +234,7 @@ namespace bbtk { GetGlobalFactory()->WriteDotFilePackagesList(ff); } - + */ }// namespace bbtk diff --git a/kernel/src/bbtkInterpreter.cxx b/kernel/src/bbtkInterpreter.cxx index 28dbfe4..e9bf1e8 100644 --- a/kernel/src/bbtkInterpreter.cxx +++ b/kernel/src/bbtkInterpreter.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkInterpreter.cxx,v $ $ Language: C++ - Date: $Date: 2008/03/03 14:55:55 $ - Version: $Revision: 1.39 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.40 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -37,7 +37,7 @@ namespace bbtk { -Interpreter* Interpreter::mGlobalInterpreter = NULL; + //Interpreter* Interpreter::mGlobalInterpreter = NULL; //======================================================================= /** @@ -45,15 +45,17 @@ Interpreter* Interpreter::mGlobalInterpreter = NULL; */ Interpreter::Interpreter() : +#ifdef _USE_WXWIDGETS_ + mWxConsole(0), +#endif mCommandLine(false) { bbtk::MessageManager::RegisterMessageType("Echo","Level>0 : Prints the 'echo' commands of the user.\n\tLevel>1 : Prints the command being interpreted",1); bbtk::MessageManager::RegisterMessageType("Interpreter","Messages of the interpreter",0); bbtkDebugMessageInc("Interpreter",9,"Interpreter::Interpreter()" <SetInterpreter(this); // For the time being, comment out previous line, and // uncomment next line to check Transcriptor @@ -291,7 +293,6 @@ Interpreter* Interpreter::mGlobalInterpreter = NULL; std::cout << "=========================================~Interpreter()" << std::endl; bbtkDebugMessageInc("Interpreter",9,"Interpreter::~Interpreter()" <mExecuter->SetCurrentFileName(words[1]); + GetExecuter()->SetCurrentFileName(words[1]); } break; case cLoad: - LoadPackage(words[1]); + GetExecuter()->GetFactory()->LoadPackage(words[1]); break; case cUnload: - UnLoadPackage(words[1]); + GetExecuter()->GetFactory()->UnLoadPackage(words[1]); break; case cQuit : @@ -1093,7 +1094,7 @@ void Interpreter::Help(const std::vector& words) { if (words[1]=="packages") { - PrintPackages(true); + GetExecuter()->GetFactory()->PrintPackages(true); return; } try @@ -1104,16 +1105,16 @@ void Interpreter::Help(const std::vector& words) { try { - HelpPackage(words[1]); + GetExecuter()->GetFactory()->HelpPackage(words[1]); #ifdef _USE_WXWIDGETS_ - if ( WxConsole::GetInstance() != 0 ) + if ( mWxConsole != 0 ) { std::string url = ConfigurationFile::GetInstance().Get_doc_path(); url += "/bbdoc/" + words[1] + "/index.html"; if (Utilities::FileExists(url)) { - WxConsole::GetInstance()->ShowHtmlPage(url); + mWxConsole->ShowHtmlPage(url); } } #endif @@ -1123,9 +1124,9 @@ void Interpreter::Help(const std::vector& words) try { std::string package; - HelpBlackBox(words[1],package); + GetExecuter()->GetFactory()->HelpBlackBox(words[1],package); #ifdef _USE_WXWIDGETS_ - if ( WxConsole::GetInstance() != 0 ) + if ( mWxConsole != 0 ) { std::string url = ConfigurationFile::GetInstance().Get_doc_path(); @@ -1133,7 +1134,7 @@ void Interpreter::Help(const std::vector& words) if (Utilities::FileExists(url)) { url += "#" + words[1]; - WxConsole::GetInstance()->ShowHtmlPage(url); + mWxConsole->ShowHtmlPage(url); } } #endif @@ -1142,7 +1143,7 @@ void Interpreter::Help(const std::vector& words) { try { - this->mExecuter->ShowRelations(words[1],"0","9999"); + GetExecuter()->ShowRelations(words[1],"0","9999"); } catch (bbtk::Exception h){ bbtkError("\""<& words) { if ( words[1]=="packages" ) { - PrintPackages(true,true); + GetExecuter()->GetFactory()->PrintPackages(true,true); return; } try { - HelpPackage(words[1],true); + GetExecuter()->GetFactory()->HelpPackage(words[1],true); } catch (bbtk::Exception f) { @@ -1531,7 +1532,7 @@ void Interpreter::Graph(const std::vector& words) bool system_display = true; #ifdef _USE_WXWIDGETS_ - if ( WxConsole::GetInstance() != 0 ) system_display = false; + if ( mWxConsole != 0 ) system_display = false; #endif if (words.size()==1) @@ -1564,8 +1565,8 @@ void Interpreter::Graph(const std::vector& words) } #ifdef _USE_WXWIDGETS_ - if ( WxConsole::GetInstance() != 0 ) - WxConsole::GetInstance()->ShowHtmlPage(page); + if ( mWxConsole != 0 ) + mWxConsole->ShowHtmlPage(page); #endif } //======================================================================= @@ -1581,7 +1582,7 @@ void Interpreter::Index(const std::string& filename, else if (type=="Packages") t = Factory::Packages; else if (type=="Adaptors") t = Factory::Adaptors; - GetGlobalFactory()->CreateHtmlIndex(t,filename); + GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename); } //======================================================================= diff --git a/kernel/src/bbtkInterpreter.h b/kernel/src/bbtkInterpreter.h index 124323b..eb8e09c 100644 --- a/kernel/src/bbtkInterpreter.h +++ b/kernel/src/bbtkInterpreter.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkInterpreter.h,v $ $ Language: C++ - Date: $Date: 2008/03/03 08:06:36 $ - Version: $Revision: 1.12 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.13 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -37,7 +37,10 @@ namespace bbtk { - +#ifdef _USE_WXWIDGETS_ + class WxConsole; +#endif + class BBTK_EXPORT Interpreter { @@ -94,8 +97,6 @@ namespace bbtk /// Destructor ~Interpreter(); - static Interpreter* mGlobalInterpreter; - /// Launches a command line interpreter (with a prompt) void CommandLineInterpreter(); @@ -167,6 +168,19 @@ namespace bbtk /// Sets the bool that indicates wether we are in command line context void SetCommandLine(bool v = true) { mCommandLine = v; } +#ifdef _USE_WXWIDGETS_ + /// Sets the WxConsole that created the interpreter (if any) + void SetWxConsole(WxConsole* c) { mWxConsole = c; } + /// Gets the WxConsole that created the interpreter (if any) + WxConsole* GetWxConsole() { return mWxConsole; } + /// Gets the WxConsole that created the interpreter (if any) - const + const WxConsole* GetWxConsole() const { return mWxConsole; } +#endif + + /// Gets the Executer + VirtualExec* GetExecuter() { return mExecuter; } + /// Gets the Executer (const) + const VirtualExec* GetExecuter() const { return mExecuter; } private: @@ -180,12 +194,14 @@ namespace bbtk //================================================================== // ATTRIBUTES - /// The factory - // bbtk::Factory* mFactory; - - /// The command executer + /// The command executer used bbtk::VirtualExec* mExecuter; +#ifdef _USE_WXWIDGETS_ + /// The WxConsole which uses the interpreter (0 if none) + bbtk::WxConsole* mWxConsole; +#endif + /// Vector of open files std::vector mFile; @@ -208,6 +224,10 @@ namespace bbtk std::deque< char* > mHistory; }; + // EO class Interpreter + + + // The "Quit" exception diff --git a/kernel/src/bbtkPackage.cxx b/kernel/src/bbtkPackage.cxx index 7d70c25..cdc1920 100644 --- a/kernel/src/bbtkPackage.cxx +++ b/kernel/src/bbtkPackage.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkPackage.cxx,v $ Language: C++ - Date: $Date: 2008/02/18 10:41:02 $ - Version: $Revision: 1.9 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or @@ -35,11 +35,12 @@ namespace bbtk const std::string& description, const std::string& version, const std::string& BBTKVersion) - : mName(name), - mAuthor(author), - mDescription(description), - mVersion(version), - mBBTKVersion(BBTKVersion) + : + mName(name), + mAuthor(author), + mDescription(description), + mVersion(version), + mBBTKVersion(BBTKVersion) { std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir(); char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1]; diff --git a/kernel/src/bbtkPackage.h b/kernel/src/bbtkPackage.h index fb7b32c..1dfc854 100644 --- a/kernel/src/bbtkPackage.h +++ b/kernel/src/bbtkPackage.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkPackage.h,v $ Language: C++ - Date: $Date: 2008/02/05 12:16:55 $ - Version: $Revision: 1.4 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or @@ -105,7 +105,19 @@ namespace bbtk const BlackBoxMapType& GetBlackBoxMap() const { return mBlackBoxMap; } BlackBoxMapType& GetBlackBoxMap() { return mBlackBoxMap; } + // Factories management + /// Adds the factory to the set of factories which use the package + void AddFactory(Factory* f) { mFactorySet.insert(f); } + /// Removes the factory from the set of factories which use the package + void RemoveFactory(Factory* f) { mFactorySet.erase(f); } + + /// Gets the set of factories which use the package + std::set& GetFactorySet() { return mFactorySet; } + /// Gets the set of factories which use the package (const) + const std::set& GetFactorySet() const { return mFactorySet; } + private: + /// The name of the package std::string mName; /// The author of the package @@ -152,13 +164,16 @@ namespace bbtk std::string mTypeOut; }; - //typedef std::string AdaptorKey; - /// The type of map of adaptor descriptors typedef std::map< AdaptorKey, BlackBoxDescriptor*> AdaptorMapType; /// The map of adaptors descriptors AdaptorMapType mAdaptorMap; + + + /// The set of factories which contain the package + std::set mFactorySet; + }; // EO class Package //==================================================================== diff --git a/kernel/src/bbtkVirtualExec.h b/kernel/src/bbtkVirtualExec.h index 96a264b..1bb48a9 100644 --- a/kernel/src/bbtkVirtualExec.h +++ b/kernel/src/bbtkVirtualExec.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkVirtualExec.h,v $ $ Language: C++ - Date: $Date: 2008/02/06 09:27:52 $ - Version: $Revision: 1.7 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -28,14 +28,16 @@ #define __bbtkVirtualExec_h__ #include "bbtkSystem.h" -#include "bbtkComplexBlackBox.h" +//#include "bbtkComplexBlackBox.h" #include "bbtkFactory.h" -#include -#include +//#include +//#include namespace bbtk { + class Interpreter; + class /*BBTK_EXPORT*/ VirtualExec // All methods are pure virtual { @@ -48,6 +50,20 @@ namespace bbtk } DialogModeType; + VirtualExec() : mInterpreter(0) {} + + /// Sets the interpreter who uses it + void SetInterpreter(Interpreter* i) { mInterpreter = i; } + /// Gets the interpreter who uses it + Interpreter* GetInterpreter() { return mInterpreter; } + /// Gets the interpreter who uses it (const) + const Interpreter* GetInterpreter() const { return mInterpreter; } + + /// Gets the factory used by the executer + virtual Factory* GetFactory() { return 0; } + /// Gets the factory used by the executer (const) + virtual const Factory* GetFactory() const { return 0; } + /// Sets the inputs of the workspace : virtual void SetInputs(const std::map& m) = 0; @@ -156,6 +172,9 @@ namespace bbtk private: + /// The interpreter which uses it (0 if none) + Interpreter* mInterpreter; + /* /// Gets the current working black box virtual ComplexBlackBoxDescriptor* Current() = 0; @@ -204,6 +223,7 @@ namespace bbtk /// Dialog mode DialogModeType mDialogMode; + */ }; } #endif diff --git a/kernel/src/bbtkWxConsole.cxx b/kernel/src/bbtkWxConsole.cxx index 78cc417..c988e33 100644 --- a/kernel/src/bbtkWxConsole.cxx +++ b/kernel/src/bbtkWxConsole.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkWxConsole.cxx,v $ Language: C++ - Date: $Date: 2008/03/03 10:48:47 $ - Version: $Revision: 1.6 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.7 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -161,6 +161,7 @@ namespace bbtk { mInstance = this; mInterpreter = new bbtk::Interpreter(); + mInterpreter->SetWxConsole(this); mInterpreter->SetCommandLine(true); //============== // Menu diff --git a/kernel/src/bbtkWxConsole.h b/kernel/src/bbtkWxConsole.h index 41ca170..7649c22 100644 --- a/kernel/src/bbtkWxConsole.h +++ b/kernel/src/bbtkWxConsole.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkWxConsole.h,v $ Language: C++ - Date: $Date: 2008/03/03 10:48:48 $ - Version: $Revision: 1.5 $ + Date: $Date: 2008/03/07 08:40:14 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -57,7 +57,14 @@ namespace bbtk WxConsole( wxWindow *parent, wxString title, wxSize size); ~WxConsole(); - static WxConsole* GetInstance() { return mInstance; } + // static WxConsole* GetInstance() { return mInstance; } + + /// Returns the Interpreter used + /// ONLY ONE FOR THE MOMENT BUT IN THE FUTURE CAN BE DIFFERENT + /// (DIFFERENT WORKSPACES) + Interpreter* GetInterpreter() { return mInterpreter; } + /// Returns the Interpreter used (const) + const Interpreter* GetInterpreter() const { return mInterpreter; } /// Sets the inputs of the workspace : /// the map is passed as is to the Executer @@ -68,7 +75,8 @@ namespace bbtk /// which creates but does not execute pipelines. void SetNoExecMode(bool b) { mInterpreter->SetNoExecMode(b); } - void SetDialogMode(Interpreter::DialogModeType t) { mInterpreter->SetDialogMode(t); } + void SetDialogMode(Interpreter::DialogModeType t) + { mInterpreter->SetDialogMode(t); } /// Runs the interpretation of a file void InterpretFile( const std::string& filename) diff --git a/packages/wxvtk/bbs/appli/ExampleBasicImageApplication.bbs b/packages/wxvtk/bbs/appli/ExampleBasicImageApplication.bbs new file mode 100644 index 0000000..da88857 --- /dev/null +++ b/packages/wxvtk/bbs/appli/ExampleBasicImageApplication.bbs @@ -0,0 +1,48 @@ + + +description "Demo of the box BasicImageApplication : creates an interactive image thresholding application" +author "laurent.guigues@creatis.insa-lyon.fr" +category "example" + +## THE APPLICATION BOX +include /home/guigues/coding/Sofa/bbtk/packages/wxvtk/bbs/boxes/bbBasicImageApplication +#include wxvtk/boxes/bbBasicImageApplication +new BasicImageApplication appli +set appli.WinTitle "ExampleBasicImageApplication" + +## THE FILTER +new BinaryThresholdImageFilter filter +connect appli.AlgorithmInput filter.In +connect filter.Out appli.AlgorithmOutput + +## THE WINDOW FOR PARAMETERS TUNING +new LayoutLine parametersWindow +new Slider upperThresholdSlider +set upperThresholdSlider.Title "upper threshold" +set upperThresholdSlider.In 100 +new Slider lowerThresholdSlider +set lowerThresholdSlider.Title "lower threshold" +set lowerThresholdSlider.In 0 +connect lowerThresholdSlider.Widget parametersWindow.Widget1 +connect upperThresholdSlider.Widget parametersWindow.Widget2 +connect upperThresholdSlider.Out filter.UpperThreshold +connect lowerThresholdSlider.Out filter.LowerThreshold + + +connect parametersWindow.Widget appli.ParametersWidget +set appli.ParametersWindowHeight 200 +set appli.ParametersWindowWidth 400 +#set appli.Refresh Reactive + +#message Process 3 +## GO ! +#message All 9 +#graph + +#message Wx 9 +exec appli +#graph + + + + diff --git a/packages/wxvtk/bbs/boxes/bbBasicImageApplication.bbs b/packages/wxvtk/bbs/boxes/bbBasicImageApplication.bbs new file mode 100644 index 0000000..d83f1a7 --- /dev/null +++ b/packages/wxvtk/bbs/boxes/bbBasicImageApplication.bbs @@ -0,0 +1,115 @@ +include wxvtk/boxes/bbDoubleSlicer +load wx +load std +load itk +load itkvtk +load vtk + + +define BasicImageApplication + +## + description "Interface of a 'standard' image application. Displays two images : before/after processing; Offers buttons : open/parameters/run/save/quit. See DemoBasicImageApplication.bbs. Screenshot :
." + author "laurent.guigues@creatis.insa-lyon.fr" + category "widget" +## + + +# WINDOWS CREATION + new LayoutSplit mainWindow + set mainWindow.Proportion 90 + + new DoubleSlicer viewer + + new LayoutLine buttonsBar + + new CommandButton openButton + new CommandButton paramButton + new CommandButton runButton + new CommandButton saveButton + new CommandButton quitButton + + connect viewer.Widget mainWindow.Widget1 + connect buttonsBar.Widget mainWindow.Widget2 + + connect openButton.Widget buttonsBar.Widget1 + connect paramButton.Widget buttonsBar.Widget2 + connect runButton.Widget buttonsBar.Widget3 + connect saveButton.Widget buttonsBar.Widget4 + connect quitButton.Widget buttonsBar.Widget5 + + set viewer.Orientation 0 + set buttonsBar.Orientation 0 + +#OPEN + set openButton.Label "Open" + set paramButton.Label "Parameters" + set saveButton.Label "Save" + new FileSelector openFileDialog + connect openButton.BoxChange openFileDialog.BoxExecute + connect openButton.BoxChange viewer.RefreshSlicer1 + set openFileDialog.Message "Select input image" + set openFileDialog.OpenSave "Open" +#READER + new MetaImageReader reader +# set reader.Filename "/home/guigues/coding/Sofa/bbtk/data/thorax.hdr" + connect openFileDialog.Out reader.In + + connect reader.Out viewer.In1 + + +# RUN + set runButton.Label "Run" + new MultipleInputs refreshViewerOut + connect refreshViewerOut.Out viewer.RefreshSlicer2 + connect runButton.BoxChange refreshViewerOut.In1 + +#QUIT + set quitButton.Label "Quit" + set quitButton.In "quit" + + +#SAVE + new ImageWriter writer + new FileSelector saveFileDialog + set saveFileDialog.BoxProcessMode Always + set saveFileDialog.DefaultFile "out.hdr" + set saveFileDialog.Message "Select output image" + set saveFileDialog.OpenSave "Save" + connect saveFileDialog.Out writer.Filename + connect saveButton.BoxChange refreshViewerOut.In2 + connect saveButton.BoxChange writer.BoxExecute + +#PARAMETERS + new LayoutSplit paramWindow + set paramWindow.Proportion 80 + set paramWindow.WinTitle "Parameters" +# new LayoutLine userParamWindow +# connect userParamWindow.Widget paramWindow.Widget1 + new CommandButton paramWindowCloseButton + set paramWindowCloseButton.Label "Close" + connect paramWindowCloseButton.Widget paramWindow.Widget2 + connect paramWindowCloseButton.BoxChange paramWindow.WinHide + connect paramButton.BoxChange paramWindow.BoxExecute + + +# INPUTS / OUTPUTS + new anyItkImagePointerRelay imageOut + connect imageOut.Out viewer.In2 + connect imageOut.Out writer.In + + input AlgorithmOutput imageOut.In "Plug here the output of your algorithm" + output AlgorithmInput reader.Out "Plug this output to the input of your algorithm" + input ParametersWidget paramWindow.Widget1 "Connect here your parameter tuning widget" + + input ParametersWindowWidth paramWindow.WinWidth "The width of the parameters window" + input ParametersWindowHeight paramWindow.WinHeight "The height of the parameters window" + input WinTitle mainWindow.WinTitle "Title of the main window" + + input Refresh viewer.BoxProcessModeSlicer2 "Set to 'Reactive' to have automatic refresh when image or parameters change" + + exec mainWindow + + +endefine + -- 2.45.1