X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fappli%2Fbbfy%2Fbbfy.cpp;h=e67bce9600757ff3c9c60d927a9cb56a9954b553;hb=e64f1a51510b44580500fd9ec30b4c937255bf75;hp=d5a62730e520254bd47e9f397fb8dd9ab0c813f9;hpb=71376d8384d5d21b5c56d36ecc8cbf31315c039a;p=bbtk.git diff --git a/kernel/appli/bbfy/bbfy.cpp b/kernel/appli/bbfy/bbfy.cpp index d5a6273..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,11 +19,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 +58,18 @@ private: vtkPolyDataAlgorithm, } BoxType; + BoxType mType; + bool mIsWidget; std::string mParentBlackBox; std::string mItkParent; std::string mVtkParent; 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,6 +77,7 @@ private: std::string mTemplateImplementation; std::vector mInclude; + std::vector mTypedef; std::string mUserConstructor; std::string mUserCopyConstructor; @@ -77,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; } @@ -87,6 +98,7 @@ private: std::vector mOutput; std::string mProcess; + std::string mCreateWidget; // std::ofstream mFile; @@ -100,10 +112,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; @@ -123,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()
@@ -164,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");
 
@@ -173,6 +170,8 @@ void bbfy::ParseXML()
   // Type 
   mGeneric = false;
   mType = STD;
+
+
   if (BB.isAttributeSet("type")) 
     {
       std::string bbtype = BB.getAttribute("type");
@@ -181,59 +180,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")) 
 	    {
-	      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);
 	}
     }
 
-  // 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 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 +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");  
@@ -370,10 +416,16 @@ 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);
      }
 }
 //==========================================================================
@@ -382,20 +434,20 @@ void bbfy::ParseXML()
 //==========================================================================
 void bbfy::BeginNamespace()
 {
-  if (mIsInNamespace)
-    {
-      mFile << "namespace "<::iterator i;
   for (i=mInclude.begin(); i!=mInclude.end(); ++i) 
     {
@@ -429,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();
 
@@ -478,7 +550,7 @@ void bbfy::CreateHeader()
   mFile << "{\n";
 
   // Interface
-  mFile << "  BBTK_USER_BLACK_BOX_INTERFACE("
+  mFile << "  BBTK_BLACK_BOX_INTERFACE("
 	<< mName << ","
 	<< mParentBlackBox << ");\n";
 
@@ -493,7 +565,11 @@ void bbfy::CreateHeader()
        (mType == vtkPolyDataAlgorithm) )
     {
       mFile << "  typedef " <name << ",\""
-	    << ioi->help << "\"," <<  ioi->type <<");\n";
+	    << ioi->descr << "\"," <<  ioi->type << ",\"" 
+	    << ioi->nature<<"\");\n";
     }
   
   // Outputs
@@ -698,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
@@ -729,6 +823,14 @@ void bbfy::CreateHeader()
 
   // 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 +851,12 @@ void bbfy::WriteGenericITKFilterHeader()
   // Class declaration and parents
   mFile << "class /*BBTK_EXPORT*/ "<::iterator ioi;
@@ -789,7 +891,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 +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
@@ -811,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
@@ -898,15 +1000,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,19 +1024,26 @@ 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 "<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;