shape.C

Go to the documentation of this file.
00001 /* Gnome gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  *
00005  * plugin_helper reports your answers as
00006 author          =Percy Zahl
00007 email                   =zahl@users.sf.net
00008 pluginname              =shape
00009 pluginmenuentry         =Shape
00010 menupath                =Math/Misc/
00011 entryplace              =Misc
00012 shortentryplace =Misc
00013 abouttext               =shape
00014 smallhelp               =shape
00015 longhelp                =shape
00016  * 
00017  * Gxsm Plugin Name: shape.C
00018  * ========================================
00019  * 
00020  * Copyright (C) 1999 The Free Software Foundation
00021  *
00022  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00023  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00024  *
00025  * This program is free software; you can redistribute it and/or modify
00026  * it under the terms of the GNU General Public License as published by
00027  * the Free Software Foundation; either version 2 of the License, or
00028  * (at your option) any later version.
00029  *
00030  * This program is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00033  * GNU General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU General Public License
00036  * along with this program; if not, write to the Free Software
00037  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00038  */
00039 
00040 
00041 /* Please do not change the Begin/End lines of this comment section!
00042  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00043  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00044  * All "% PlugInXXX" commentary tags are mandatory
00045  * All "% OptPlugInXXX" tags are optional and can be removed or commented in
00046  * --------------------------------------------------------------------------------
00047 % BeginPlugInDocuSection
00048 % PlugInDocuCaption: Create a shape polygon from lines
00049 % PlugInName: shape
00050 % PlugInAuthor: Percy Zahl
00051 % PlugInAuthorEmail: zahl@users.sf.net
00052 % PlugInMenuPath: Math/Misc/Shape
00053 
00054 % PlugInDescription
00055 A brief description goes here.
00056 
00057 % PlugInUsage
00058 Call \GxsmMenu{Math/Misc/Shape}.
00059 
00060 %% OptPlugInSection: replace this by the section caption
00061 %all following lines until next tag are going into this section
00062 %...
00063 
00064 %% OptPlugInSubSection: replace this line by the subsection caption
00065 %all following lines until next tag are going into this subsection
00066 %...
00067 
00068 %% you can repeat OptPlugIn(Sub)Sections multiple times!
00069 
00070 %% OptPlugInSources
00071 %The active channel is used as data source.
00072 
00073 %% OptPlugInObjects
00074 %A optional rectangle is used for data extraction...
00075 
00076 %% OptPlugInDest
00077 %The computation result is placed into an existing math channel, else into a new created math channel.
00078 
00079 %% OptPlugInConfig
00080 %describe the configuration options of your plug in here!
00081 
00082 %% OptPlugInFiles
00083 %Does it uses, needs, creates any files? Put info here!
00084 
00085 %% OptPlugInRefs
00086 %Any references?
00087 
00088 %% OptPlugInKnownBugs
00089 %Are there known bugs? List! How to work around if not fixed?
00090 
00091 %% OptPlugInNotes
00092 %If you have any additional notes
00093 
00094 %% OptPlugInHints
00095 %Any tips and tricks?
00096 
00097 % EndPlugInDocuSection
00098  * -------------------------------------------------------------------------------- 
00099  */
00100 
00101 #include <gtk/gtk.h>
00102 #include "config.h"
00103 #include "gxsm/plugin.h"
00104 
00105 // Plugin Prototypes
00106 static void shape_init( void );
00107 static void shape_about( void );
00108 static void shape_configure( void );
00109 static void shape_cleanup( void );
00110 
00111 // Math-Run-Function, use only one of (automatically done :=)
00112  static gboolean shape_run( Scan *Src);
00113 
00114 // Fill in the GxsmPlugin Description here
00115 GxsmPlugin shape_pi = {
00116   NULL,                   // filled in and used by Gxsm, don't touch !
00117   NULL,                   // filled in and used by Gxsm, don't touch !
00118   0,                      // filled in and used by Gxsm, don't touch !
00119   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00120                           // filled in here by Gxsm on Plugin load, 
00121                           // just after init() is called !!!
00122   // ----------------------------------------------------------------------
00123   // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc
00124   "shape-"
00125 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00126   "M1S"
00127 #else
00128   "M2S"
00129 #endif
00130   "-Misc",
00131   // Plugin's Category - used to autodecide on Pluginloading or ignoring
00132   // NULL: load, else
00133   // example: "+noHARD +STM +AFM"
00134   // load only, if "+noHARD: no hardware" and Instrument is STM or AFM
00135   // +/-xxxHARD und (+/-INST or ...)
00136   NULL,
00137   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00138   "shape",                   
00139   // Author(s)
00140   "Percy Zahl",
00141   // Menupath to position where it is appendet to
00142   N_("_Math/_Misc/"),
00143   // Menuentry
00144   N_("Shape"),
00145   // help text shown on menu
00146   N_("shape"),
00147   // more info...
00148   "shape",
00149   NULL,          // error msg, plugin may put error status msg here later
00150   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00151   // init-function pointer, can be "NULL", 
00152   // called if present at plugin load
00153   shape_init,  
00154   // query-function pointer, can be "NULL", 
00155   // called if present after plugin init to let plugin manage it install itself
00156   NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00157   // about-function, can be "NULL"
00158   // can be called by "Plugin Details"
00159   shape_about,
00160   // configure-function, can be "NULL"
00161   // can be called by "Plugin Details"
00162   shape_configure,
00163   // run-function, can be "NULL", if non-Zero and no query defined, 
00164   // it is called on menupath->"plugin"
00165   NULL, // run should be "NULL" for Gxsm-Math-Plugin !!!
00166   // cleanup-function, can be "NULL"
00167   // called if present at plugin removeal
00168   shape_cleanup
00169 };
00170 
00171 // special math Plugin-Strucure, use
00172 GxsmMathOneSrcNoDestPlugin shape_m1s_pi = {
00173    // math-function to run, see prototype(s) above!!
00174    shape_run
00175  };
00176 
00177 // Text used in Aboutbox, please update!!
00178 static const char *about_text = N_("Gxsm shape Plugin\n\n"
00179                                    "shape");
00180 
00181 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00182 // Essential Plugin Function!!
00183 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00184   shape_pi.description = g_strdup_printf(N_("Gxsm MathOneArg shape plugin %s"), VERSION);
00185   return &shape_pi; 
00186 }
00187 
00188 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 
00189 // used to find out which Math Type the Plugin is!! 
00190 // Essential Plugin Function!!
00191 GxsmMathOneSrcNoDestPlugin *get_gxsm_math_one_src_no_dest_plugin_info( void ) {
00192   return &shape_m1s_pi; 
00193 }
00194 
00195 /* Here we go... */
00196 // init-Function
00197 static void shape_init(void)
00198 {
00199   PI_DEBUG (DBG_L2, "shape Plugin Init");
00200 }
00201 
00202 // about-Function
00203 static void shape_about(void)
00204 {
00205   const gchar *authors[] = { shape_pi.authors, NULL};
00206   gtk_widget_show(gnome_about_new ( shape_pi.name,
00207                                     VERSION,
00208                                     N_("(C) 2000 the Free Software Foundation"),
00209                                     about_text,
00210                                     authors,
00211                                     NULL, NULL, NULL
00212                                     ));
00213 }
00214 
00215 // configure-Function
00216 static void shape_configure(void)
00217 {
00218   if(shape_pi.app)
00219     shape_pi.app->message("shape Plugin Configuration");
00220 }
00221 
00222 // cleanup-Function
00223 static void shape_cleanup(void)
00224 {
00225   PI_DEBUG (DBG_L2, "shape Plugin Cleanup");
00226 }
00227 
00228 typedef struct {
00229         double x,y;
00230 } dvec;
00231 
00232 typedef struct {
00233         dvec *p1, *p2, *v;
00234 } dseg;
00235 
00236 void intersection (dseg *s1, dseg *s2, dvec &p){
00237         double la, mu;
00238         la=mu=0.;
00239         
00240 
00241 }
00242 
00243 // run-Function
00244  static gboolean shape_run(Scan *Src)
00245 {
00246      int n_obj = Src->number_of_object ();
00247      if (n_obj < 3) 
00248              return MATH_SELECTIONERR;
00249 
00250      // count all Line objects
00251      int n_lines=0;
00252      for (int i=0; i<n_obj; i++)
00253              if (!strncmp ((Src->get_object_data (i))->get_name (), "Line", 4) )
00254                      ++n_lines;
00255 
00256      dvec *p1  = new dvec[n_lines];
00257      dvec *p2  = new dvec[n_lines];
00258      dvec *v12 = new dvec[n_lines];
00259 
00260      int k=0;
00261      for (int i=0; i<n_obj; i++)
00262              if (!strncmp ((Src->get_object_data (i))->get_name (), "Line", 4) ){
00263                      (Src->get_object_data (i))->get_xy (0, p1[k].x, p1[k].y);
00264                      (Src->get_object_data (i))->get_xy (1, p2[k].x, p2[k].y);
00265                      // convert to pixels
00266                      Point2D p;
00267                      Src->World2Pixel (p1[k].x, p1[k].y, p.x, p.y);
00268                      p1[k].x = p.x; 
00269                      p1[k].y = p.y;
00270                      Src->World2Pixel (p2[k].x, p2[k].y, p.x, p.y);
00271                      p2[k].x = p.x; 
00272                      p2[k].y = p.y;
00273                      v12[k].x = p2[k].x - p1[k].x; 
00274                      v12[k].y = p2[k].y - p1[k].y; 
00275                      ++k;
00276              }
00277 
00278      delete [] p1;
00279      delete [] p2;
00280      delete [] v12;
00281 
00282   return MATH_OK;
00283 }
00284 
00285 

Generated on Sat Apr 1 09:04:22 2006 for GXSM by  doxygen 1.4.6