X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=kernel%2Fappli%2Fbbfy%2Fbbfy.cpp;h=e67bce9600757ff3c9c60d927a9cb56a9954b553;hb=e64f1a51510b44580500fd9ec30b4c937255bf75;hp=64120471d5fa2883012204fa218108a190ee9356;hpb=f303df63e2a2e33d698c974858f288058d980ae4;p=bbtk.git diff --git a/kernel/appli/bbfy/bbfy.cpp b/kernel/appli/bbfy/bbfy.cpp index 6412047..e67bce9 100644 --- a/kernel/appli/bbfy/bbfy.cpp +++ b/kernel/appli/bbfy/bbfy.cpp @@ -3,7 +3,7 @@ #endif #include -#include "xmlParser.h" +#include "bbtkXML.h" #include #include #include @@ -19,6 +19,10 @@ public: }; //========================================================================== +const std::string itkImageToImageFilterString = "ITK_ImageToImageFilter"; +const std::string vtkImageAlgorithmString = "VTK_ImageAlgorithm"; +const std::string vtkPolyDataAlgorithmString = "VTK_PolyDataAlgorithm"; + //========================================================================== class bbfy { @@ -54,6 +58,7 @@ private: vtkPolyDataAlgorithm, } BoxType; + BoxType mType; bool mIsWidget; std::string mParentBlackBox; @@ -72,6 +77,7 @@ private: std::string mTemplateImplementation; std::vector mInclude; + std::vector mTypedef; std::string mUserConstructor; std::string mUserCopyConstructor; @@ -81,7 +87,8 @@ private: { std::string name; std::string type; - std::string help; + std::string nature; + std::string descr; std::string special; std::string generic_type; } @@ -109,6 +116,8 @@ bbfy::bbfy(const std::string& filename, const std::string& output_path, bool verbose) { + mIsWidget = false; + mFilename = filename; mPackage = package; mNamespace = "bb" + mPackage; @@ -132,27 +141,6 @@ void bbfy::CreateBlackBox() //========================================================================== -//========================================================================== -void GetTextOrClear(const XMLNode& node, std::string& var) -{ - 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);
-    }
-}
-//==========================================================================
-
 
 //==========================================================================
 void bbfy::ParseXML()
@@ -173,7 +161,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 +180,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")) 
 	    {
-	      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("vtkparent"),mVtkParent);
 	  // 
 	}
-      else 
+    else if (bbtype == vtkPolyDataAlgorithmString )
+	{
+	  mType = vtkPolyDataAlgorithm;
+	  // Looks for  tag
+	  if (!BB.nChildNode("vtkparent")) 
+	    {
+	      throw bbfyException("Error : blackbox type '"
+				  +vtkPolyDataAlgorithmString
+				  +"' but no  tag found (mandatory)");
+	    }
+	  bbtk::GetTextOrClear(BB.getChildNode("vtkparent"),mVtkParent);
+	  // 
+	}
+     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 +245,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 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 +378,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,13 +419,13 @@ 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);
      }
 }
 //==========================================================================
@@ -462,7 +471,10 @@ void bbfy::CreateHeader()
     }
   
   // If is widget 
-  mFile << "#ifdef _USE_WXWIDGETS_\n";
+  if (mIsWidget)
+    {
+      mFile << "#ifdef _USE_WXWIDGETS_\n";
+    }
 
   // Prevent multiple inclusions
   std::string included("__bb");
@@ -480,6 +492,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();
 
@@ -529,7 +550,7 @@ void bbfy::CreateHeader()
   mFile << "{\n";
 
   // Interface
-  mFile << "  BBTK_USER_BLACK_BOX_INTERFACE("
+  mFile << "  BBTK_BLACK_BOX_INTERFACE("
 	<< mName << ","
 	<< mParentBlackBox << ");\n";
 
@@ -544,7 +565,11 @@ void bbfy::CreateHeader()
        (mType == vtkPolyDataAlgorithm) )
     {
       mFile << "  typedef " <name << ",\""
-	    << ioi->help << "\"," <<  ioi->type <<");\n";
+	    << ioi->descr << "\"," <<  ioi->type << ",\"" 
+	    << ioi->nature<<"\");\n";
     }
   
   // Outputs
@@ -760,7 +791,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
@@ -795,7 +827,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 +855,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 +905,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 +913,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
@@ -965,14 +1000,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,21 +1024,21 @@ 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 "<