C#: How do I instantiate a class in C#, like showin this C++ example -


i've translated following c++ code c#, cant determine , how put class instance. if using:

customanalysis test = new customanalysis(); 

it receive errormessage, telling me class instantiated rhino3d, , therefore i'm not supposed it. need create reference class can it's static member m_am_id variable created base-class.

this line im having trouble with:

static class czanalysisvam thezanalysisvam; 

thanks in advance.

c++ code:

////////////////////////////////////////////////////////////////// // // begin z analysis mode class //   // example demonstrates how add false color // analysis mode rhino.  example uses false color indicate // world "z" coordinate.  // {df4688c-9671-4389-ac41-515b8693a783} static const guid false_color_example_analysis_mode_id = { 0xdf4688c, 0x9671, 0x4389, { 0xac, 0x41, 0x51, 0x5b, 0x86, 0x93, 0xa7, 0x83 } };  class czanalysisvam : public crhinovisualanalysismode { public:   czanalysisvam();   ~czanalysisvam();    // virtual crhinovisualanalysismode override   void getanalysismodename( on_wstring& name ) const;    // virtual crhinovisualanalysismode override   bool objectsupportsanalysismode( const crhinoobject* object ) const;    // virtual crhinovisualanalysismode override   void updatevertexcolors(              const crhinoobject* object,              on_simplearray<const on_mesh *>& meshes              ) const;    // virtual crhinovisualanalysismode override   bool showisocurves() const;    // virtual crhinovisualanalysismode override   void drawmeshobject(            const crhinomeshobject& mesh_object,           crhinodisplaypipeline& dp           );    // virtual crhinovisualanalysismode override   void drawbrepobject(            const crhinobrepobject& brep_object,           crhinodisplaypipeline& dp           );    bool m_bshowisocurves;    // simple example provides false color based on   // world z coordinate.   details, see implementation   // of falsecolor function.   on_interval m_z_range;     on_interval m_hue_range;    on_color falsecolor(double z) const;    // returns mapping tag used detect when   // meshes colors need set.  details, see   // implementation  of mappingtag , updatevertexcolors.   on_mappingtag mappingtag() const; };   // 1 , instance of czanalysisvam object. // crhinovisualanalysismode constructor registers mode // rhino.  class must not destroyed while rhino // active. static class czanalysisvam thezanalysisvam;  czanalysisvam::czanalysisvam()  : crhinovisualanalysismode( false_color_example_analysis_mode_id,                             crhinovisualanalysismode::false_color_style                             ) {   m_bshowisocurves = true;    // in real plug-in, user interface allow   // user change these intervals.    m_z_range.set(-10.0,10.0);   m_hue_range.set(0.0,4.0*on_pi/3.0); // red green blue }  czanalysisvam::~czanalysisvam() { }  void czanalysisvam::getanalysismodename( on_wstring& name ) const {   // name shows in object properties details   // report when object in analysis mode.   name = l"z analysis"; }  bool czanalysisvam::objectsupportsanalysismode( const crhinoobject* object ) const {   // function should return true if analysis mode works   // on object.  example works on meshes , breps,   // version of objectsupportsanalysismode looks this.    bool rc = false;   if ( object )   {     switch(object->objecttype())     {     case on::mesh_object:       if ( crhinomeshobject::cast(object) )         rc = true;       break;      case on::surface_object:     case on::polysrf_filter:     case on::brep_object:       if ( crhinobrepobject::cast(object) )         rc = true;       break;     }   }   return rc; }  on_mappingtag czanalysisvam::mappingtag() const {   on_mappingtag mt;    // since false colors shown change if   // mesh transformed, have initialize   // transformation.   mt.m_mesh_xform.identity();    // analysis mode id passed    // crhinovisualanalysismode constructor. use   // m_am_id member , code alwasy    // work correctly.   mt.m_mapping_id = m_am_id;    // 32 bit crc or information used   // set false colors.   // example, m_z_range , m_hue_range   // intervals controlthe colors, calculate    // crc.   mt.m_mapping_crc = 0;   mt.m_mapping_crc = on_crc32(mt.m_mapping_crc,sizeof(m_z_range),&m_z_range);   mt.m_mapping_crc = on_crc32(mt.m_mapping_crc,sizeof(m_hue_range),&m_hue_range);    return mt; }  on_color czanalysisvam::falsecolor(double z) const {   // simple example of 1 way change number    // color.   double s = m_z_range.normalizedparameterat(z);   if ( s < 0.0 ) s = 0.0; else if (s > 1.0) s = 1.0;   double hue = m_hue_range.parameterat(s);   on_color c;   c.sethsv( hue, 1.0, 1.0 );   return c; }  void czanalysisvam::updatevertexcolors(              const crhinoobject* object,              on_simplearray<const on_mesh *>& meshes              ) const {   // rhino calls function when time   // set false colors on analysis mesh vertices.   // breps, there 1 mesh per face.  mesh objects,   // there single mesh.   const int count = meshes.count();   if (count > 0 )   {     // "mapping tag" used determine if colors     // need set.     on_mappingtag mt = mappingtag();      const on_mesh * const * mesh_list = meshes.array();     ( int mi = 0; mi < count; mi++ )     {       const on_mesh* mesh = mesh_list[mi];       if ( mesh && mt.compare(mesh->m_ctag) )       {         // mesh's mapping tag different ours. either         // mesh has no false colors, has false colors set         // analysis mode, has false colors set using         // different m_z_range[]/m_hue_range[] values, or         // mesh has been moved.  in case, need set         // false colors ones want.          const int vcount = mesh->m_v.count();         on_simplearray<on_color>& vertex_colors = const_cast<on_mesh*>(mesh)->m_c;         vertex_colors.setcount(0);     // in case else had set colors         vertex_colors.reserve(vcount); // efficiency         (int vi = 0; vi < vcount; vi++ )         {           double z = mesh->m_v[vi].z;           on_color c = falsecolor(z);           vertex_colors.append(c);         }          // set mesh's color tag          const_cast<on_mesh*>(mesh)->m_ctag = mt;       }     }   } }  bool czanalysisvam::showisocurves() const {   // shaded analysis modes work on breps have   // option of showing or hiding isocurves.  run   // built-in rhino zebraanalysis see how rhino handles   // user interface.  if controlling iso-curve visability    // feature want support, provide user   // interface set member variable.   return m_bshowisocurves; }  // // end z analysis mode class //  ////////////////////////////////////////////////////////////////// 

c# code:

using system; using system.collections; using system.collections.generic; using system.text;  using rma.rhino; using rma.opennurbs;  namespace myplugin1 {        public class customanalysis : mrhinovisualanalysismode     {           static guid false_color_example_analysis_mode_id = new guid("{b0cbd23a-089b-4fb2-a61a-6de1238e7b74}");          public oninterval m_z_range;         public oninterval m_hue_range;          bool m_bshowisocurves;          public customanalysis():base(false_color_example_analysis_mode_id,irhinovisualanalysismode.analysis_style.false_color_style)          {             m_bshowisocurves = true;              // in real plug-in, user interface allow             // user change these intervals.              m_z_range.set(-10.0, 10.0);             m_hue_range.set(0.0, 4.0 * math.pi / 3.0); // red green blue          }           public override string getanalysismodename()         {             return "kineticmode";         }           public override bool objectsupportsanalysismode(irhinoobject rh_object)         {             // function should return true if analysis mode works             // on object.  example works on meshes , breps,             // version of objectsupportsanalysismode looks this.             onobject obj = rh_object.duplicateonobject();              boolean rc = false;             if (null != rh_object && null != obj)             {                 switch (rh_object.objecttype())                 {                     case ion.object_type.mesh_object:                         if (null != mrhinomeshobject.cast(obj))                              rc = true;                         break;                      case ion.object_type.surface_object:                     case ion.object_type.polysrf_filter:                     case ion.object_type.brep_object:                         if (null != mrhinobrepobject.cast(obj))                              rc = true;                         break;                 }             }             return rc;         }          public override void updatevertexcolors(irhinoobject rh_object, onmesh[] meshes)         {             int count = meshes.length;              if (count > 0)             {                 // "mapping tag" used determine if colors                 // need set.                 onmappingtag mt = mappingtag();                  //const on_mesh * const * mesh_list = meshes.array();                 (int mi = 0; mi < count; mi++)                 {                     onmesh mesh = meshes[mi];                     if (null != mesh && mt.compare(mesh.m_ctag) > 0)                     {                         // mesh's mapping tag different ours. either                         // mesh has no false colors, has false colors set                         // analysis mode, has false colors set using                         // different m_z_range[]/m_hue_range[] values, or                         // mesh has been moved.  in case, need set                         // false colors ones want.                          int vcount = mesh.m_v.count();                          arrayoncolor vertex_colors = onmesh.cast(mesh).m_c;                          vertex_colors.setcount(0);     // in case else had set colors                         vertex_colors.reserve(vcount); // efficiency                          (int vi = 0; vi < vcount; vi++)                         {                             double z = mesh.m_v[vi].z;                             oncolor c = falsecolor(z);                             vertex_colors.append(c);                         }                          // set mesh's color tag                          mesh.m_ctag = mt;                       }                 }             }         }          public override bool showisocurves()         {             return m_bshowisocurves;         }          public override void drawmeshobject(irhinomeshobject mesh_object, mrhinodisplaypipeline dp)         {             base.drawmeshobject(mesh_object, dp);         }          public override void drawbrepobject(irhinobrepobject brep_object, mrhinodisplaypipeline dp)         {             base.drawbrepobject(brep_object, dp);         }          public onmappingtag mappingtag()         {              onmappingtag mt = null;              // since false colors shown change if             // mesh transformed, have initialize             // transformation.             mt.m_mesh_xform.identity();              // analysis mode id passed              // crhinovisualanalysismode constructor. use             // m_am_id member , code alwasy              // work correctly.             mt.m_mapping_id = m_am_id;              // 32 bit crc or information used             // set false colors.             // example, m_z_range , m_hue_range             // intervals control colors, calculate              // crc.             mt.m_mapping_crc = 0;             //mt.m_mapping_crc = on_crc32(mt.m_mapping_crc, m_z_range.length, m_z_range);             //mt.m_mapping_crc = on_crc32(mt.m_mapping_crc, m_hue_range.length, m_hue_range);             ontexturemapping thomas = new ontexturemapping();               return mt;          }           public oncolor falsecolor(double z)         {              double s = m_z_range.normalizedparameterat(z);              if (s < 0.0) s = 0.0; else if (s > 1.0) s = 1.0;              double hue = m_hue_range.parameterat(s);              oncolor c = new oncolor();              c.sethsv(hue, 1.0, 1.0);              return c;          }           ~customanalysis() { }      } } 

if need static member of customanalysis class in c#, can access customanalysis.m_am_id. since member static, access using class itself, not object of class.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -