X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fappli%2Fbbfy%2Fbbfy.cpp;h=43f89023c53ed59c3d9f223eed78d26fe0347a03;hb=49cb3ed3b5b7e58ab54dd3b6eb4ad8adee824ef2;hp=0c7972ae52f72b2348b36408a71bd0f68eacd3ce;hpb=a26195c366a89795288009cf7e20f11afa494970;p=bbtk.git diff --git a/kernel/appli/bbfy/bbfy.cpp b/kernel/appli/bbfy/bbfy.cpp index 0c7972a..43f8902 100644 --- a/kernel/appli/bbfy/bbfy.cpp +++ b/kernel/appli/bbfy/bbfy.cpp @@ -1,9 +1,35 @@ +/* +# --------------------------------------------------------------------- +# +# 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. +# ------------------------------------------------------------------------ */ + #ifdef WIN32 #define _CRT_SECURE_NO_DEPRECATE #endif #include -#include "xmlParser.h" +#include "bbtkXML.h" #include #include #include @@ -19,11 +45,17 @@ public: }; //========================================================================== +const std::string itkImageToImageFilterString = "ITK_ImageToImageFilter"; +const std::string vtkImageAlgorithmString = "VTK_ImageAlgorithm"; +const std::string vtkPolyDataAlgorithmString = "VTK_PolyDataAlgorithm"; + //========================================================================== class bbfy { public: - bbfy(const std::string& filename, const std::string& output_path = "", + bbfy(const std::string& filename, + const std::string& package = "PACKAGE_NAME", + const std::string& output_path = "", bool verbose = false); void CreateBlackBox(); @@ -52,15 +84,18 @@ private: vtkPolyDataAlgorithm, } BoxType; + BoxType mType; + bool mIsWidget; std::string mParentBlackBox; std::string mItkParent; - std::string mVtkParent; + std::string mVtkObject; bool mGeneric; std::string mAuthor; std::string mDescription; + std::string mCategory; std::string mPackage; - bool mIsInNamespace; + // bool mIsInNamespace; std::string mNamespace; // int mNbTemplateParam; std::vector mTemplateParam; @@ -68,16 +103,18 @@ private: std::string mTemplateImplementation; std::vector mInclude; + std::vector mTypedef; - std::string mUserConstructor; - std::string mUserCopyConstructor; - std::string mUserDestructor; + std::string mUserSetDefaultValues; + std::string mUserInitializeProcessing; + std::string mUserFinalizeProcessing; typedef struct { std::string name; std::string type; - std::string help; + std::string nature; + std::string descr; std::string special; std::string generic_type; } @@ -87,12 +124,15 @@ private: std::vector mOutput; std::string mProcess; + std::string mCreateWidget; // std::ofstream mFile; std::string mHName; std::string mCxxName; + void AlertString(); + }; //========================================================================== @@ -100,10 +140,16 @@ private: //========================================================================== bbfy::bbfy(const std::string& filename, + const std::string& package, const std::string& output_path, bool verbose) { + mIsWidget = false; + mFilename = filename; + mPackage = package; + mNamespace = "bb" + mPackage; + mOutputPath = output_path; mVerbose = verbose; @@ -122,32 +168,22 @@ void bbfy::CreateBlackBox() } //========================================================================== - -//========================================================================== -void GetTextOrClear(const XMLNode& node, std::string& var) +void bbfy::AlertString() { - if (node.nText()>0) - { - var = node.getText(); - } - else if (node.nClear()>0) - { - var = node.getClear().lpszValue; - } - else - { - std::string mess("Error : element <"); - mess += node.getName(); - mess += "> : no text nor
 clear tag found";
-      throw bbfyException(mess);
-    }
+	
+      mFile << "//===== \n";
+      mFile << "// Before editing this file, make sure it's a file of your own ";
+      mFile << "(i.e.: it wasn't generated from xml description; if so : your modifications will be lost)\n";
+      mFile << "//===== \n";
+	  
 }
-//==========================================================================
-
 
 //==========================================================================
 void bbfy::ParseXML()
 {
+
+
+
   XMLResults* res = new XMLResults;
   XMLNode BB = XMLNode::parseFile(mFilename.c_str(),"blackbox",res);
 
@@ -164,7 +200,7 @@ void bbfy::ParseXML()
   // Name
   if (!BB.isAttributeSet("name")) 
     {
-      throw bbfyException("Error : no 'name' attribute found (mandatory)");
+      throw bbfyException("Error :  tag : no 'name' attribute found (mandatory)");
     }
   mName = BB.getAttribute("name");
 
@@ -173,6 +209,8 @@ void bbfy::ParseXML()
   // Type 
   mGeneric = false;
   mType = STD;
+
+
   if (BB.isAttributeSet("type")) 
     {
       std::string bbtype = BB.getAttribute("type");
@@ -181,59 +219,77 @@ void bbfy::ParseXML()
 	  mGeneric = false;
 	  mType = STD;
 	}
-      else if (bbtype=="itkImageToImageFilter")
+      else if (bbtype==itkImageToImageFilterString)
 	{
 	  mType = itkImageToImageFilter;
 	  // Looks for  tag
 	  if (!BB.nChildNode("itkparent")) 
 	    {
-	      throw bbfyException("Error : blackbox type 'itkImageToImageFilter' but no  tag found (mandatory)");
+	      throw bbfyException("Error : blackbox type '"+itkImageToImageFilterString+"' but no  tag found (mandatory)");
 	    }
-	  GetTextOrClear(BB.getChildNode("itkparent"),mItkParent);
+	  bbtk::GetTextOrClear(BB.getChildNode("itkparent"),mItkParent);
 	  // 
 	  mGeneric = false;
 	  if (BB.isAttributeSet("generic")) mGeneric=true;
 	}
-      else if ((bbtype=="vtkImageAlgorithm") || (bbtype=="vtkPolyDataAlgorithm"))
+      else if (bbtype == vtkImageAlgorithmString)
 	{
 	  mType = vtkImageAlgorithm;
-	  // Looks for  tag
-	  if (!BB.nChildNode("vtkparent")) 
+	  // Looks for  tag
+	  if (!BB.nChildNode("vtkobject")) 
 	    {
-	      throw bbfyException("Error : blackbox type 'vtkImageAlgorithm' but no  tag found (mandatory)");
+	      throw bbfyException("Error : blackbox type '"
+				  +vtkImageAlgorithmString
+				  +"' but no  tag found (mandatory)");
 	    }
-	  GetTextOrClear(BB.getChildNode("vtkparent"),mVtkParent);
+	  bbtk::GetTextOrClear(BB.getChildNode("vtkobject"),mVtkObject);
 	  // 
 	}
-      else 
+    else if (bbtype == vtkPolyDataAlgorithmString )
+	{
+	  mType = vtkPolyDataAlgorithm;
+	  // Looks for  tag
+	  if (!BB.nChildNode("vtkobject")) 
+	    {
+	      throw bbfyException("Error : blackbox type '"
+				  +vtkPolyDataAlgorithmString
+				  +"' but no  tag found (mandatory)");
+	    }
+	  bbtk::GetTextOrClear(BB.getChildNode("vtkobject"),mVtkObject);
+	  // 
+	}
+     else 
 	{
 	  std::string mess("Error : blackbox type '");
 	  mess += bbtype;
-	  mess += "' unknown (types are 'standard','itkfilter')";
+	  mess += "' unknown. Known types :";
+	  mess += "'" + itkImageToImageFilterString + "' ";
+	  mess += "'" + vtkImageAlgorithmString + "' ";
+	  mess += "'" + vtkPolyDataAlgorithmString + "' ";
 	  throw bbfyException(mess);
 	}
     }
 
-  // Parent black box
-  if (!BB.nChildNode("parentblackbox")) 
+  // Is a widget box ?
+  if (BB.isAttributeSet("widget")) 
     {
-      throw bbfyException("Error : no  tag found (mandatory)");
-   }
-  GetTextOrClear(BB.getChildNode("parentblackbox"),mParentBlackBox);
-
-  // Package
-  if (!BB.nChildNode("package")) 
+      mIsWidget = true;
+      mParentBlackBox = "bbtk::WxBlackBox";
+      mInclude.push_back("bbtkWxBlackBox.h");
+    }
+  else 
     {
-      throw bbfyException("Error : no  tag found (mandatory)");
-   }
-  GetTextOrClear(BB.getChildNode("package"),mPackage);
+      mIsWidget = false;
+      mParentBlackBox = "bbtk::AtomicBlackBox";
+      mInclude.push_back("bbtkAtomicBlackBox.h");
+    }
 
   // Author
   int i,j;
   for (i=0,j=0; i 0)
@@ -281,7 +350,7 @@ void bbfy::ParseXML()
 	{
 	  mTemplateDeclaration += "class ";
 	  std::string val;
-	  GetTextOrClear(BB.getChildNode("template",&j),val);
+	  bbtk::GetTextOrClear(BB.getChildNode("template",&j),val);
 	  mTemplateDeclaration += val;
 	  mTemplateDeclaration +=  ",";
 	  mTemplateImplementation += val;
@@ -290,7 +359,7 @@ void bbfy::ParseXML()
 	}
       mTemplateDeclaration += "class ";
       std::string val;
-      GetTextOrClear(BB.getChildNode("template",&j),val);
+      bbtk::GetTextOrClear(BB.getChildNode("template",&j),val);
       mTemplateDeclaration += val;
       mTemplateDeclaration +=  ">";
       mTemplateImplementation += val;
@@ -302,33 +371,48 @@ void bbfy::ParseXML()
   for (i=0,j=0; i attribute 'name' not found (mandatory)");
 	}
+      io.name = n.getAttribute("name");
       if (!n.isAttributeSet("type"))
 	{
-	  throw bbfyException("Error :  attribute 'type' not found (mandatory)");
+	  throw bbfyException("Error :  attribute 'type' not found (mandatory)");
 	}
-
-      IO io;
-      io.name = n.getAttribute("name");
       io.type = n.getAttribute("type"); 
-      GetTextOrClear(n,io.help);
+      if (!n.isAttributeSet("description"))
+	{
+	  throw bbfyException("Error :  attribute 'description' not found (mandatory)");
+	}
+      io.descr = n.getAttribute("description"); 
 
       if (n.isAttributeSet("special")) 
 	{
 	  io.special =  n.getAttribute("special");  
 	}
 
+      if (n.isAttributeSet("nature")) 
+	{
+	  io.nature =  n.getAttribute("nature");  
+	}
+
       if (n.isAttributeSet("generic_type")) 
 	{
 	  io.generic_type =  n.getAttribute("generic_type");  
@@ -340,26 +424,34 @@ void bbfy::ParseXML()
   // Outputs
   for (i=0,j=0; i attribute 'name' not found (mandatory)");
 	}
+      io.name = n.getAttribute("name"); 
       if (!n.isAttributeSet("type"))
 	{
-	  throw bbfyException("Error :  attribute 'type' not found (mandatory)");
+	  throw bbfyException("Error :  attribute 'type' not found (mandatory)");
 	}
-
-      IO io;
-      io.name = n.getAttribute("name"); 
       io.type = n.getAttribute("type"); 
-      GetTextOrClear(n,io.help);
+      if (!n.isAttributeSet("description"))
+	{
+	  throw bbfyException("Error :  attribute 'description' not found (mandatory)");
+	}
+      io.descr = n.getAttribute("description"); 
 
       if (n.isAttributeSet("special")) 
 	{
 	  io.special =  n.getAttribute("special");  
 	}
 
+      if (n.isAttributeSet("nature")) 
+	{
+	  io.nature =  n.getAttribute("nature");  
+	}
+
       if (n.isAttributeSet("generic_type")) 
 	{
 	  io.generic_type =  n.getAttribute("generic_type");  
@@ -370,11 +462,42 @@ void bbfy::ParseXML()
 
 
   // Process
-  // Process tag given ?
+  // process tag given ?
    if (BB.nChildNode("process"))
      {
-       GetTextOrClear(BB.getChildNode("process"),mProcess);
+		 bbtk::GetTextOrClear(BB.getChildNode("process"),mProcess);
      }
+     
+  // CreateWidget
+  // createwidget tag given ?
+   if (BB.nChildNode("createwidget"))
+     {
+       bbtk::GetTextOrClear(BB.getChildNode("createwidget"),mCreateWidget);
+     }
+
+
+
+
+
+
+
+   // OBSOLETE/UNSUPPORTED TAGS
+  // WARN IF OBSOLETE TAGS PROVIDED
+  if (BB.nChildNode("constructor"))
+    {
+      std::cout << "WARNING !!! The tag  is obsolete !!"< is obsolete !!"< is obsolete !!"<::iterator i;
   for (i=mInclude.begin(); i!=mInclude.end(); ++i) 
     {
@@ -429,6 +565,15 @@ void bbfy::CreateHeader()
   if (mGeneric) mFile << "#include \"bbitkImage.h\"\n";
   mFile << "\n";
 
+  if (mType == itkImageToImageFilter )
+    {
+      mFile << "#include \"bbtkItkBlackBoxMacros.h\"\n";
+    }
+  else if ( (mType == vtkImageAlgorithm) ||
+	    (mType == vtkPolyDataAlgorithm) )
+    {
+      mFile << "#include \"bbtkVtkBlackBoxMacros.h\"\n";
+    }
   // Namespace
   BeginNamespace();
 
@@ -441,9 +586,8 @@ void bbfy::CreateHeader()
     }
   
   // Class declaration and parents
-  mFile << "class /*BBTK_EXPORT*/ "<::iterator ioi;
@@ -524,7 +667,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="itk input")
 	{
 	  mFile << "  BBTK_DECLARE_ITK_INPUT(" 
-		<< "itkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -534,7 +676,6 @@ void bbfy::CreateHeader()
 	{
 	  if (mType == vtkImageAlgorithm) {
 	  mFile << "  BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -542,7 +683,6 @@ void bbfy::CreateHeader()
 	  } 
 	  else if (mType == vtkPolyDataAlgorithm) {
 	  mFile << "  BBTK_DECLARE_POLY_DATA_ALGORITHM_INPUT(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -552,7 +692,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="itk parameter")
 	{
 	  mFile << "  BBTK_DECLARE_ITK_PARAM(" 
-		<< "itkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -561,7 +700,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="vtk parameter")
 	{
 	  mFile << "  BBTK_DECLARE_VTK_PARAM(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -577,6 +715,7 @@ void bbfy::CreateHeader()
 	  throw bbfyException(mess);
 	}
     }
+
   
   // Outputs
   for (ioi=mOutput.begin(); ioi!=mOutput.end(); ++ioi) 
@@ -592,7 +731,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="itk output")
 	{
 	  mFile << "  BBTK_DECLARE_ITK_OUTPUT(" 
-		<< "itkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -601,7 +739,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="vtk output")
 	{
 	  mFile << "  BBTK_DECLARE_VTK_OUTPUT(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -618,28 +755,34 @@ void bbfy::CreateHeader()
 	}
     }
   
-
   // Process
   if ((mType == STD)||(mProcess.size()))
     {
-      mFile << "  BBTK_PROCESS(DoProcess);\n" ;
-      mFile << "  void DoProcess();\n";
+      mFile << "  BBTK_PROCESS(Process);\n" ;
+      mFile << "  void Process();\n";
     }
   else if (mType == itkImageToImageFilter)
     {   
-      mFile << "  BBTK_PROCESS(itkParent::Update);\n" ;
+      mFile << "  BBTK_ITK_PROCESS();\n" ;
     }
   else if ((mType == vtkImageAlgorithm) ||
 	   (mType == vtkPolyDataAlgorithm) )
 
     {   
-      mFile << "  BBTK_PROCESS(vtkParent::Update);\n" ;
+      mFile << "  BBTK_VTK_PROCESS();\n" ;
     }
 
-  // EO black box declaration
-  mFile << "};\n\n";
+  // CreateWidget
+  if (mIsWidget) 
+    {
+       mFile << "  BBTK_CREATE_WIDGET(CreateWidget);\n" ;
+       mFile << "  void CreateWidget(wxWindow*);\n";
+    }
 
+	AlertString();
 
+  // EO black box declaration
+  mFile << "};\n\n";
 
   // BO black box description
   if (mTemplateParam.size()==0)
@@ -664,13 +807,22 @@ void bbfy::CreateHeader()
     {
       throw bbfyException("template bb with more than 1 templ param not impl");
     } 
-  
+
+
   // Author
   mFile << "BBTK_AUTHOR(\""<name << ",\""
-	    << ioi->help << "\"," <<  ioi->type <<");\n";
+	    << ioi->descr << "\"," <<  ioi->type << ",\"" 
+	    << ioi->nature<<"\");\n";
     }
   
   // Outputs
@@ -698,7 +851,8 @@ void bbfy::CreateHeader()
 	  mFile << "BBTK_OUTPUT(";
 	} 
       mFile << mName << "," << ioi->name << ",\""
-	    << ioi->help << "\"," <<  ioi->type <<");\n";
+	    << ioi->descr << "\"," <<  ioi->type << ",\"" 
+	    << ioi->nature<<"\");\n";
     }
   
   // EO black box description
@@ -726,9 +880,18 @@ void bbfy::CreateHeader()
       WriteGenericITKFilterHeader();
     }
 
+	AlertString();
 
   // EO namespace
   EndNamespace();
+  
+  // Prevent multiple inclusions
+  mFile << "#endif // " << included <<"\n";
+  // If is widget 
+  if (mIsWidget)
+    {
+      mFile << "#endif // _USE_WXWIDGETS_\n";
+    }
 
   // EOF
   mFile << "\n";
@@ -749,12 +912,12 @@ void bbfy::WriteGenericITKFilterHeader()
   // Class declaration and parents
   mFile << "class /*BBTK_EXPORT*/ "<::iterator ioi;
@@ -789,7 +952,7 @@ void bbfy::WriteGenericITKFilterHeader()
 
   // BO black box description
   mFile << "BBTK_BEGIN_DESCRIBE_BLACK_BOX("
-	<< mName << "Generic,bbtk::UserBlackBox);\n";
+	<< mName << "Generic,bbtk::AtomicBlackBox);\n";
   mFile << "BBTK_NAME(\"" << mName <<"\");\n";
 
   // Author
@@ -803,7 +966,7 @@ void bbfy::WriteGenericITKFilterHeader()
     {
       mFile << "BBTK_INPUT(";
       mFile << mName << "Generic," << ioi->name << ",\""
-	    << ioi->help << "\"," <<  ioi->generic_type <<");\n";
+	    << ioi->descr << "\"," <<  ioi->generic_type <<");\n";
     }
   
   // Outputs
@@ -811,7 +974,7 @@ void bbfy::WriteGenericITKFilterHeader()
     {
       mFile << "BBTK_OUTPUT(";
       mFile << mName << "Generic," << ioi->name << ",\""
-	    << ioi->help << "\"," <<  ioi->generic_type <<");\n";
+	    << ioi->descr << "\"," <<  ioi->generic_type <<");\n";
     }
   
   // EO black box description
@@ -835,7 +998,7 @@ void bbfy::WriteGenericITKFilterHeader()
   mFile << "template \n"
 	<< "void "<()<<\",\"<()\"<bbUpdate();\n"
 	<< "  this->bbSetOutputOut( new itkImage( f->bbGetOutputOut() ) );\n"
 	<< "  f->UnRegister();\n"
-	<< "  bbtkDebugDecTab(\"Core\",9);\n"
+	<< "  bbtkDebugDecTab(\"Kernel\",9);\n"
 	<< "}\n\n";
   //=================================================================
 
@@ -882,7 +1045,10 @@ void bbfy::CreateCode()
       mess += "\"";
       throw bbfyException(mess);
     }
-  
+
+	AlertString();
+
+
   // Includes
   // Header of the class
   mFile << "#include \"" << mHName << "\"\n";
@@ -898,15 +1064,15 @@ void bbfy::CreateCode()
   if (mTemplateParam.size()>0) 
     {
       // Implementation
-      mFile << "BBTK_USER_BLACK_BOX_TEMPLATE_IMPLEMENTATION("
+      mFile << "BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION("
 	    << mName << ","  
 	    << mParentBlackBox << ");\n";
      
       if (mGeneric) 
 	{	
 	  // Implementation
-	  mFile << "BBTK_USER_BLACK_BOX_IMPLEMENTATION("
-		<< mName << "Generic,bbtk::UserBlackBox);\n";
+	  mFile << "BBTK_BLACK_BOX_IMPLEMENTATION("
+		<< mName << "Generic,bbtk::AtomicBlackBox);\n";
 	  // Package
 	  mFile << "BBTK_ADD_BLACK_BOX_TO_PACKAGE("
 		<< mPackage << ","
@@ -922,36 +1088,60 @@ void bbfy::CreateCode()
 	    << mName << ")\n";
 
       // Implementation
-      mFile << "BBTK_USER_BLACK_BOX_IMPLEMENTATION("
+      mFile << "BBTK_BLACK_BOX_IMPLEMENTATION("
 	    << mName << ","  
-	    << mParentBlackBox << ");\n";
- 
-      // Process
-      if ((mType == STD)||(mProcess.size()))
+	    << mParentBlackBox << ");\n"; 
+    }
+  // Process
+  if ((mType == STD)||(mProcess.size()))
+    {
+	AlertString();
+      mFile << "void "<4) 
+  if (argc<2 || argc>5) 
     {
-      std::cerr << "usage : "<< argv[0] <<" xml_file [output_path] [-q]" << std::endl;
+      std::cerr << "usage : "<< argv[0] <<" xml_file [package_name] [output_path] [-q]" << std::endl;
       return 1;
     }
 
   try 
     {
+      std::string package("PACKAGE_NAME");
       std::string output_path("");
       bool verbose = true;
-      if (argc>2) output_path = argv[2];
-      if (argc>3) verbose = false;
+      if (argc>2) package = argv[2];
+      if (argc>3) output_path = argv[3];
+      if (argc>4) verbose = false;
       
-      bbfy B(argv[1],output_path,verbose);
+      bbfy B(argv[1],package,output_path,verbose);
     }
   catch (bbfyException e)
     {
-      std::cerr << e.mMessage << std::endl;
+      std::cerr << argv[0] << "  " << argv[1] << std::endl
+		<< e.mMessage << std::endl;
       return 1;
     }
   return 0;