X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fappli%2Fbbfy%2Fbbfy.cpp;h=347babc2b89afcf162727fc8b7eeff4cd77c41a5;hb=c7a94dfa5f48e30bb931b45bd6d7c42954ad9ed5;hp=07adbba644fb635ff3468d9cacc4566122935dbb;hpb=bd20c3d3b1a07722b5f2d4661cf9f945dafda3ef;p=bbtk.git diff --git a/kernel/appli/bbfy/bbfy.cpp b/kernel/appli/bbfy/bbfy.cpp index 07adbba..347babc 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,7 +58,9 @@ private: vtkPolyDataAlgorithm, } BoxType; + BoxType mType; + bool mIsWidget; std::string mParentBlackBox; std::string mItkParent; std::string mVtkParent; @@ -61,7 +69,7 @@ private: std::string mDescription; std::string mCategory; std::string mPackage; - bool mIsInNamespace; + // bool mIsInNamespace; std::string mNamespace; // int mNbTemplateParam; std::vector mTemplateParam; @@ -69,6 +77,7 @@ private: std::string mTemplateImplementation; std::vector mInclude; + std::vector mTypedef; std::string mUserConstructor; std::string mUserCopyConstructor; @@ -78,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; } @@ -88,6 +98,7 @@ private: std::vector mOutput; std::string mProcess; + std::string mCreateWidget; // std::ofstream mFile; @@ -101,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; @@ -124,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()
@@ -165,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");
 
@@ -174,6 +170,8 @@ void bbfy::ParseXML()
   // Type 
   mGeneric = false;
   mType = STD;
+
+
   if (BB.isAttributeSet("type")) 
     {
       std::string bbtype = BB.getAttribute("type");
@@ -182,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");  
@@ -349,26 +380,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");  
@@ -379,10 +418,17 @@ 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);
      }
 }
 //==========================================================================
@@ -391,20 +437,20 @@ void bbfy::ParseXML()
 //==========================================================================
 void bbfy::BeginNamespace()
 {
-  if (mIsInNamespace)
-    {
-      mFile << "namespace "<::iterator i;
   for (i=mInclude.begin(); i!=mInclude.end(); ++i) 
     {
@@ -438,6 +495,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();
 
@@ -450,9 +516,8 @@ void bbfy::CreateHeader()
     }
   
   // Class declaration and parents
-  mFile << "class /*BBTK_EXPORT*/ "<special=="itk input")
 	{
 	  mFile << "  BBTK_DECLARE_ITK_INPUT(" 
-		<< "itkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -543,7 +620,6 @@ void bbfy::CreateHeader()
 	{
 	  if (mType == vtkImageAlgorithm) {
 	  mFile << "  BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -551,7 +627,6 @@ void bbfy::CreateHeader()
 	  } 
 	  else if (mType == vtkPolyDataAlgorithm) {
 	  mFile << "  BBTK_DECLARE_POLY_DATA_ALGORITHM_INPUT(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -561,7 +636,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="itk parameter")
 	{
 	  mFile << "  BBTK_DECLARE_ITK_PARAM(" 
-		<< "itkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -570,7 +644,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="vtk parameter")
 	{
 	  mFile << "  BBTK_DECLARE_VTK_PARAM(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -601,7 +674,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="itk output")
 	{
 	  mFile << "  BBTK_DECLARE_ITK_OUTPUT(" 
-		<< "itkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -610,7 +682,6 @@ void bbfy::CreateHeader()
       else if (ioi->special=="vtk output")
 	{
 	  mFile << "  BBTK_DECLARE_VTK_OUTPUT(" 
-		<< "vtkParent,"
 		<< ioi->name
 		<< ","
 		<< ioi->type
@@ -627,28 +698,33 @@ 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";
+    }
 
 
+  // EO black box declaration
+  mFile << "};\n\n";
 
   // BO black box description
   if (mTemplateParam.size()==0)
@@ -682,6 +758,11 @@ void bbfy::CreateHeader()
   
   // Category
   mFile << "BBTK_CATEGORY(\""<name << ",\""
-	    << ioi->help << "\"," <<  ioi->type <<");\n";
+	    << ioi->descr << "\"," <<  ioi->type << ",\"" 
+	    << ioi->nature<<"\");\n";
     }
   
   // Outputs
@@ -710,7 +792,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
@@ -741,6 +824,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";
@@ -765,7 +856,7 @@ void bbfy::WriteGenericITKFilterHeader()
   mFile << "{\n";
 
   // Interface
-  mFile << "  BBTK_USER_BLACK_BOX_INTERFACE("
+  mFile << "  BBTK_BLACK_BOX_INTERFACE("
 	<< mName << "Generic,bbtk::AtomicBlackBox);\n";
 
   // Inputs
@@ -815,7 +906,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
@@ -823,7 +914,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
@@ -910,14 +1001,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("
@@ -934,27 +1025,35 @@ 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;