X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fappli%2Fbbfy%2Fbbfy.cpp;h=43f89023c53ed59c3d9f223eed78d26fe0347a03;hb=cfad95b6e08e6e53846ffcda7fbc5932065f2c47;hp=64120471d5fa2883012204fa218108a190ee9356;hpb=f303df63e2a2e33d698c974858f288058d980ae4;p=bbtk.git diff --git a/kernel/appli/bbfy/bbfy.cpp b/kernel/appli/bbfy/bbfy.cpp index 6412047..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,6 +45,10 @@ public: }; //========================================================================== +const std::string itkImageToImageFilterString = "ITK_ImageToImageFilter"; +const std::string vtkImageAlgorithmString = "VTK_ImageAlgorithm"; +const std::string vtkPolyDataAlgorithmString = "VTK_PolyDataAlgorithm"; + //========================================================================== class bbfy { @@ -54,11 +84,12 @@ 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; @@ -72,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; } @@ -98,6 +131,8 @@ private: std::string mHName; std::string mCxxName; + void AlertString(); + }; //========================================================================== @@ -109,6 +144,8 @@ bbfy::bbfy(const std::string& filename, const std::string& output_path, bool verbose) { + mIsWidget = false; + mFilename = filename; mPackage = package; mNamespace = "bb" + mPackage; @@ -131,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);
 
@@ -173,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");
 
@@ -192,35 +219,53 @@ 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);
 	}
     }
@@ -239,28 +284,12 @@ void bbfy::ParseXML()
       mInclude.push_back("bbtkAtomicBlackBox.h");
     }
 
-  /*
-  // Parent black box
-  if (!BB.nChildNode("parentblackbox")) 
-    {
-      throw bbfyException("Error : no  tag found (mandatory)");
-   }
-  GetTextOrClear(BB.getChildNode("parentblackbox"),mParentBlackBox);
-
-  // Package
-  if (!BB.nChildNode("package")) 
-    {
-      throw bbfyException("Error : no  tag found (mandatory)");
-   }
-  GetTextOrClear(BB.getChildNode("package"),mPackage);
-  */
-
   // Author
   int i,j;
   for (i=0,j=0; i 0)
@@ -318,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;
@@ -327,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;
@@ -339,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");  
@@ -377,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");  
@@ -410,14 +465,39 @@ void bbfy::ParseXML()
   // 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"))
      {
-       GetTextOrClear(BB.getChildNode("createwidget"),mCreateWidget);
+       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) 
     {
@@ -480,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();
 
@@ -492,9 +586,8 @@ void bbfy::CreateHeader()
     }
   
   // Class declaration and parents
-  mFile << "class /*BBTK_EXPORT*/ "<::iterator ioi;
@@ -575,7 +667,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="itk input")
 	{
 	  mFile << "  BBTK_DECLARE_ITK_INPUT(" 
-		<< "itkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -585,7 +676,6 @@ void bbfy::CreateHeader()
 	{
 	  if (mType == vtkImageAlgorithm) {
 	  mFile << "  BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -593,7 +683,6 @@ void bbfy::CreateHeader()
 	  } 
 	  else if (mType == vtkPolyDataAlgorithm) {
 	  mFile << "  BBTK_DECLARE_POLY_DATA_ALGORITHM_INPUT(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -603,7 +692,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="itk parameter")
 	{
 	  mFile << "  BBTK_DECLARE_ITK_PARAM(" 
-		<< "itkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -612,7 +700,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="vtk parameter")
 	{
 	  mFile << "  BBTK_DECLARE_VTK_PARAM(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -628,6 +715,7 @@ void bbfy::CreateHeader()
 	  throw bbfyException(mess);
 	}
     }
+
   
   // Outputs
   for (ioi=mOutput.begin(); ioi!=mOutput.end(); ++ioi) 
@@ -643,7 +731,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="itk output")
 	{
 	  mFile << "  BBTK_DECLARE_ITK_OUTPUT(" 
-		<< "itkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -652,7 +739,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="vtk output")
 	{
 	  mFile << "  BBTK_DECLARE_VTK_OUTPUT(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -669,37 +755,35 @@ 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" ;
     }
 
   // CreateWidget
   if (mIsWidget) 
     {
-       mFile << "  BBTK_CREATE_WIDGET(DoCreateWidget);\n" ;
-       mFile << "  void DoCreateWidget();\n";
+       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)
     {
@@ -723,7 +807,8 @@ 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
@@ -760,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
@@ -788,6 +880,7 @@ void bbfy::CreateHeader()
       WriteGenericITKFilterHeader();
     }
 
+	AlertString();
 
   // EO namespace
   EndNamespace();
@@ -795,7 +888,10 @@ void bbfy::CreateHeader()
   // Prevent multiple inclusions
   mFile << "#endif // " << included <<"\n";
   // If is widget 
-  mFile << "#endif // _USE_WXWIDGETS_\n";
+  if (mIsWidget)
+    {
+      mFile << "#endif // _USE_WXWIDGETS_\n";
+    }
 
   // EOF
   mFile << "\n";
@@ -820,7 +916,7 @@ void bbfy::WriteGenericITKFilterHeader()
   mFile << "{\n";
 
   // Interface
-  mFile << "  BBTK_USER_BLACK_BOX_INTERFACE("
+  mFile << "  BBTK_BLACK_BOX_INTERFACE("
 	<< mName << "Generic,bbtk::AtomicBlackBox);\n";
 
   // Inputs
@@ -870,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
@@ -878,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
@@ -949,7 +1045,10 @@ void bbfy::CreateCode()
       mess += "\"";
       throw bbfyException(mess);
     }
-  
+
+	AlertString();
+
+
   // Includes
   // Header of the class
   mFile << "#include \"" << mHName << "\"\n";
@@ -965,14 +1064,14 @@ 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("
+	  mFile << "BBTK_BLACK_BOX_IMPLEMENTATION("
 		<< mName << "Generic,bbtk::AtomicBlackBox);\n";
 	  // Package
 	  mFile << "BBTK_ADD_BLACK_BOX_TO_PACKAGE("
@@ -989,43 +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()))
     {
-      mFile << "void "<