(* ::Package:: *)

BeginPackage["XMLfiles`",{"stereographic`","domain`"}]


XMLfiles::usage="This package provides a function genAxelFile which basically construct an XML file from different Mathematica computations. The XML file is used
for visualization purposes in the algebraic geometric modeler Axel: http://axel.inria.fr/. The Mathematica computations are performed with the Mathematica packages 
named stereographic and domain. The generated XML file contains the stereographic projection in 3D of a plane complex algebraic curve with a singularity in the origin.
Use ?genAxelFile for more information on the function."
genAxelFile::usage="The function genAxelFile[complexBivPolyEqn, {list_of_variables}, value, name] uses the operations provided from the packages stereographic and domain
on the bivariate complex polynomial complexBivPolyEqn in two variables specified by list_of_variables and on the value. The function uses these operations to 
automatically generate an XML file."


genAxelFile[eqn_,{m_,n_},epsilon_,name_]:=Module[{poly1,poly2,p1,p2,elemXML,elemXMLstring,fileaxl},
poly1:=getFixPolys[eqn,{m,n},epsilon][[1]];
poly2:=getFixPolys[eqn,{m,n},epsilon][[2]];
p1:=ExportString[poly1,"Text"];
p2:=ExportString[poly2,"Text"];
elemXML:=XMLElement["axl",{},
{
XMLElement["surface",{"type"->"implicit","name"->"ImplicitSurface0","color"->"250 0 0"},
	{
		XMLElement["domain",{},{"-5.01 5.01", "-5.01 5.01", "-3.01 3.01"}],
		XMLElement["polynomial",{"variables"->"x y z"},{p1}]
        }
                      ],
  XMLElement["surface",{"type"->"implicit","name"->"ImplicitSurface0","color"->"85 170 255"},
          {
		XMLElement["domain",{},{"-5.01 5.01", "-5.01 5.01", "-3.01 3.01"}],
		XMLElement["polynomial",{"variables"->"x y z"},{p2}]
        }
                       ],
XMLElement["curve",{"type"->"implicit","name"->"icurve_0","color"->"175 34 255"},
          {
		XMLElement["domain",{},{"-5.01 5.01", "-5.01 5.01", "-3.01 3.01"}],
		XMLElement["polynomial",{"variables"->"x y z"},{p1}],
		XMLElement["polynomial",{"variables"->"x y z"},{p2}]
        }
                     ],
XMLElement["script",{},{}]
}
];
elemXMLstring:=ExportString[elemXML,"XML"];
fileaxl:=Export[StringJoin["/Users/madalinahodorog/Desktop/myAxelFiles/",name],elemXMLstring,"Text"];
{fileaxl}
]


If[$Notebooks,
   CellPrint[Cell[#, "Print", FontColor -> Black, 
                              CellFrame -> 0.5, 
                              Background -> LightGray]]&,
   Print
  ]["XML files - by Madalina Hodorog -  A package that creates an XML files from several Mathematica computations."]


EndPackage[]
