]> Creatis software - bbtk.git/blobdiff - kernel/appli/bbfy/bbfy.cpp
* Created vtk package
[bbtk.git] / kernel / appli / bbfy / bbfy.cpp
index 07adbba644fb635ff3468d9cacc4566122935dbb..64120471d5fa2883012204fa218108a190ee9356 100644 (file)
@@ -23,7 +23,9 @@ public:
 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();
@@ -53,6 +55,7 @@ private:
     }
     BoxType;
   BoxType mType;
+  bool mIsWidget;
   std::string mParentBlackBox;
   std::string mItkParent;
   std::string mVtkParent;
@@ -61,7 +64,7 @@ private:
   std::string mDescription;
   std::string mCategory;
   std::string mPackage;
-  bool mIsInNamespace;
+  // bool mIsInNamespace;
   std::string mNamespace;
   // int mNbTemplateParam;
   std::vector<std::string> mTemplateParam;
@@ -88,6 +91,7 @@ private:
   std::vector<IO> mOutput;
 
   std::string mProcess;
+  std::string mCreateWidget;
 
   //
   std::ofstream mFile;
@@ -101,10 +105,14 @@ private:
 
 //==========================================================================
 bbfy::bbfy(const std::string& filename, 
+          const std::string& package,
           const std::string& output_path,
           bool verbose)
 {
   mFilename = filename;
+  mPackage = package;
+  mNamespace = "bb" + mPackage;
+
   mOutputPath = output_path;
   mVerbose = verbose;
 
@@ -174,6 +182,8 @@ void bbfy::ParseXML()
   // Type 
   mGeneric = false;
   mType = STD;
+
+
   if (BB.isAttributeSet("type")) 
     {
       std::string bbtype = BB.getAttribute("type");
@@ -215,6 +225,21 @@ void bbfy::ParseXML()
        }
     }
 
+  // Is a widget box ?
+  if (BB.isAttributeSet("widget")) 
+    {
+      mIsWidget = true;
+      mParentBlackBox = "bbtk::WxBlackBox";
+      mInclude.push_back("bbtkWxBlackBox.h");
+    }
+  else 
+    {
+      mIsWidget = false;
+      mParentBlackBox = "bbtk::AtomicBlackBox";
+      mInclude.push_back("bbtkAtomicBlackBox.h");
+    }
+
+  /*
   // Parent black box
   if (!BB.nChildNode("parentblackbox")) 
     {
@@ -228,6 +253,7 @@ void bbfy::ParseXML()
       throw bbfyException("Error : no <package> tag found (mandatory)");
    }
   GetTextOrClear(BB.getChildNode("package"),mPackage);
+  */
 
   // Author
   int i,j;
@@ -255,13 +281,15 @@ void bbfy::ParseXML()
     }
 
   // Namespace
+  /*
   mIsInNamespace = false;
   if (BB.nChildNode("namespace"))
     {
       mIsInNamespace = true;
       GetTextOrClear(BB.getChildNode("namespace"),mNamespace);
     }
+  */
+
   // UserConstructor body
   if (BB.nChildNode("constructor"))
     {
@@ -379,11 +407,17 @@ void bbfy::ParseXML()
 
 
   // Process
-  // Process tag given ?
+  // process tag given ?
    if (BB.nChildNode("process"))
      {
        GetTextOrClear(BB.getChildNode("process"),mProcess);
      }
+  // CreateWidget
+  // createwidget tag given ?
+   if (BB.nChildNode("createwidget"))
+     {
+       GetTextOrClear(BB.getChildNode("createwidget"),mCreateWidget);
+     }
 }
 //==========================================================================
 
@@ -391,20 +425,20 @@ void bbfy::ParseXML()
 //==========================================================================
 void bbfy::BeginNamespace()
 {
-  if (mIsInNamespace)
-    {
-      mFile << "namespace "<<mNamespace <<"\n{\n\n";
-    }
+  //  if (mIsInNamespace)
+  // {
+  mFile << "namespace "<<mNamespace <<"\n{\n\n";
+  //  }
 }
 //==========================================================================
 
 //==========================================================================
 void bbfy::EndNamespace()
 {
-  if (mIsInNamespace)
-    {
-      mFile << "}\n// EO namespace "<<mNamespace<<"\n\n";
-    }
+  // if (mIsInNamespace)
+  //  {
+  mFile << "}\n// EO namespace "<<mNamespace<<"\n\n";
+  //  }
 }
 //==========================================================================
 
@@ -427,9 +461,17 @@ void bbfy::CreateHeader()
       throw bbfyException(mess);
     }
   
+  // If is widget 
+  mFile << "#ifdef _USE_WXWIDGETS_\n";
+
+  // Prevent multiple inclusions
+  std::string included("__bb");
+  included += mPackage + mName + "_h_INCLUDED__";
+  mFile << "#ifndef " << included <<"\n";
+  mFile << "#define " << included <<"\n";
 
   // Includes 
-  mFile << "#include \"bbtkAtomicBlackBox.h\"\n";
+  //  mFile << "#include \"bbtkAtomicBlackBox.h\"\n";
   std::vector<std::string>::iterator i;
   for (i=mInclude.begin(); i!=mInclude.end(); ++i) 
     {
@@ -645,6 +687,14 @@ void bbfy::CreateHeader()
       mFile << "  BBTK_PROCESS(vtkParent::Update);\n" ;
     }
 
+  // CreateWidget
+  if (mIsWidget) 
+    {
+       mFile << "  BBTK_CREATE_WIDGET(DoCreateWidget);\n" ;
+       mFile << "  void DoCreateWidget();\n";
+    }
+
+
   // EO black box declaration
   mFile << "};\n\n";
 
@@ -741,6 +791,11 @@ void bbfy::CreateHeader()
 
   // EO namespace
   EndNamespace();
+  
+  // Prevent multiple inclusions
+  mFile << "#endif // " << included <<"\n";
+  // If is widget 
+  mFile << "#endif // _USE_WXWIDGETS_\n";
 
   // EOF
   mFile << "\n";
@@ -936,17 +991,24 @@ void bbfy::CreateCode()
       // Implementation
       mFile << "BBTK_USER_BLACK_BOX_IMPLEMENTATION("
            << mName << ","  
-           << mParentBlackBox << ");\n";
-      // Process
-      if ((mType == STD)||(mProcess.size()))
-       {
-         mFile << "void "<<mName<<"::DoProcess()\n{\n";
-         mFile << mProcess << "\n";
-         mFile << "}\n";
-       }
+           << mParentBlackBox << ");\n"; 
+    }
+  // Process
+  if ((mType == STD)||(mProcess.size()))
+    {
+      mFile << "void "<<mName<<"::DoProcess()\n{\n";
+      mFile << mProcess << "\n";
+      mFile << "}\n";
+    }
+  // CreateWidget
+  if (mIsWidget)
+    {
+      mFile << "void "<<mName<<"::DoCreateWidget()\n{\n";
+      mFile << mCreateWidget << "\n";
+      mFile << "}\n";
     }
   
+
   // User constr / copy constr / destr implementation
   mFile <<"void "<<mName<<"::bbUserConstructor()"<<std::endl;
   mFile << "{"<<std::endl;
@@ -986,20 +1048,22 @@ void bbfy::CreateCode()
 int main(int argc, char **argv)
 {
   
-  if (argc<2 || argc>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)
     {