Salome HOME
Merge remote-tracking branch 'origin/master' into V9_dev
[modules/hexablock.git] / src / HEXABLOCK / HexVector.cxx
index 53075b11fea6f13a49eb48b7df7690d5342e036e..0e4c5b09ca622a6be7181a8e8747d93b94f6c23e 100755 (executable)
@@ -1,13 +1,32 @@
 
-// C++ : Gestion des aretes
+// C++ : Gestion des vecteurs
 
+// Copyright (C) 2009-2016  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 #include "HexVector.hxx"
+#include "HexXmlWriter.hxx"
 
 BEGIN_NAMESPACE_HEXA
 
 // ======================================================== Constructeur
 Vector::Vector (Document* doc, double dx, double dy, double dz)
-      : EltBase (doc)
+      : EltBase (doc, EL_VECTOR)
 {
     v_dx = dx;
     v_dy = dy;
@@ -59,5 +78,105 @@ int Vector::calculNormale (double& nx, double& ny, double& nz)
    ny = -v_dx / norme;
    return HOK;  
 }
+// ========================================================= saveXml 
+void Vector::saveXml (XmlWriter* xml)
+{
+   char buffer[12], coord[80];
+
+   sprintf (coord, "%g %g %g", v_dx, v_dy, v_dz);
+
+   xml->openMark     ("Vector");
+   xml->addAttribute ("id",    getName (buffer));
+   xml->addAttribute ("coord", coord);
+   if (el_name!=buffer) 
+       xml->addAttribute ("name", el_name);
+   xml->closeMark ();
+}
+// ========================================================= getAngleX
+double Vector::getAngleX ()
+{
+   static const double Epsilon = 1e-6;
+
+   double norme = getNorm ();
+   if (norme < Epsilon)
+      return 0.0;
+
+   double kos = v_dx / norme;
+   double deg = acos(kos) * 180.0 / M_PI;
+   return deg;
+}
+// ===================================================== getCoord
+double Vector::getCoord (int dir) 
+{
+   double val = 0;
+   switch (dir)
+          {
+          case dir_x : val = v_dx; 
+               break;
+          case dir_y : val = v_dy; 
+               break;
+          case dir_z : val = v_dz; 
+               break;
+          }
+   return val;
+}
+// ===================================================== renormer
+int Vector::renormer() 
+{
+   double dn = getNorm ();
+   if (dn < 1e-30) 
+      return HERR;
+
+   v_dx /= dn;
+   v_dy /= dn;
+   v_dz /= dn;
+
+   return HOK;
+}
+// ===================================================== vectoriel
+void Vector::vectoriel (Vector* a, Vector*b)
+{
+   v_dx =   a->v_dy * b->v_dz - b->v_dy * a->v_dz; 
+   v_dy =   a->v_dz * b->v_dx - b->v_dz * a->v_dx; 
+   v_dz =   a->v_dx * b->v_dy - b->v_dx * a->v_dy; 
+}
+
+// ===================================================== getCoord
+double* Vector::getCoord (double coord[])
+{
+   coord [dir_x] = v_dx;
+   coord [dir_y] = v_dy;
+   coord [dir_z] = v_dz;
+   return coord;
+}
+// ===================================================== getUnitVector
+int Vector::getUnitVector (double coord[])
+{
+   coord [dir_x] = v_dx;
+   coord [dir_y] = v_dy;
+   coord [dir_z] = v_dz;
+   int ier  = normer_vecteur (coord);
+   return ier;
+}
+// ===================================================== multiplier
+void Vector::multiplier (double scalaire)
+{
+   v_dx *= scalaire;
+   v_dy *= scalaire;
+   v_dz *= scalaire;
+}
+// ===================================================== dump
+void Vector::dump ()
+{
+   printf ("Vector ");
+   printName (" = ");
+   if (NOT isHere ())
+      {
+      printf ("(*** deleted ***)\n");
+      return;
+      }
+
+   printf ("(%g, %g, %g)\n", v_dx,v_dy,v_dz);
+}
 
 END_NAMESPACE_HEXA