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 =stefan 00007 pluginname =shiftarea 00008 pluginmenuentry =Shift-Area 00009 menupath =Math/Transformations/ 00010 entryplace =Transformations 00011 shortentryplace =TR 00012 abouttext =Shift area with line object. 00013 smallhelp =Shift area to connect correctly. 00014 longhelp =Shift area does this and that. 00015 * 00016 * Gxsm Plugin Name: shiftarea.C 00017 * ======================================== 00018 * 00019 * Copyright (C) 1999 The Free Software Foundation 00020 * 00021 * Authors: Percy Zahl <zahl@fkp.uni-hannover.de> 00022 * additional features: Andreas Klust <klust@fkp.uni-hannover.de> 00023 * 00024 * This program is free software; you can redistribute it and/or modify 00025 * it under the terms of the GNU General Public License as published by 00026 * the Free Software Foundation; either version 2 of the License, or 00027 * (at your option) any later version. 00028 * 00029 * This program is distributed in the hope that it will be useful, 00030 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00031 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00032 * GNU General Public License for more details. 00033 * 00034 * You should have received a copy of the GNU General Public License 00035 * along with this program; if not, write to the Free Software 00036 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00037 */ 00038 00039 /* Please do not change the Begin/End lines of this comment section! 00040 * this is a LaTeX style section used for auto generation of the PlugIn Manual 00041 * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks! 00042 * All "% PlugInXXX" commentary tags are mandatory 00043 * All "% OptPlugInXXX" tags are optional 00044 * -------------------------------------------------------------------------------- 00045 % BeginPlugInDocuSection 00046 % PlugInDocuCaption: Transformation Shift-Area 00047 % PlugInName: shiftarea 00048 % PlugInAuthor: Stefan Schr\"oder 00049 % PlugInAuthorEmail: stefan_fkp@users.sf.net 00050 % PlugInMenuPath: Math/Transformation/Shift Area 00051 00052 % PlugInDescription 00053 00054 This plugin shifts the lower part of a scan with respect to the upper 00055 part, according to a chosen line. 00056 00057 % PlugInUsage 00058 Choose a line Object an connect the two points with your line, that shall 00059 be brought together. The green point must be lower than the red one. 00060 00061 % OptPlugInSources 00062 You need one active scan and a line object. Rectangle works two, the 00063 diagonal will work like the line. 00064 00065 % OptPlugInObjects 00066 If a rectangle is selected the calculated information applies to the 00067 content of the rectangle. Otherwise, the whole scan is analyzed. 00068 00069 % OptPlugInDest 00070 A new scan will be created, which contains the unchanged upper part and the 00071 shifted lower part, connected. 00072 00073 %% OptPlugInConfig 00074 %None. 00075 00076 %% OptPlugInKnownBugs 00077 %None? 00078 00079 %% OptPlugInNotes 00080 %None. 00081 % EndPlugInDocuSection 00082 * 00083 -------------------------------------------------------------------------------- 00084 */ 00085 00086 #include <gtk/gtk.h> 00087 #include "config.h" 00088 #include "gxsm/plugin.h" 00089 00090 // Plugin Prototypes 00091 static void shiftarea_init( void ); 00092 static void shiftarea_about( void ); 00093 static void shiftarea_configure( void ); 00094 static void shiftarea_cleanup( void ); 00095 00096 // Define Type of math plugin here, only one line should be commented in!! 00097 #define GXSM_ONE_SRC_PLUGIN__DEF 00098 // #define GXSM_TWO_SRC_PLUGIN__DEF 00099 00100 // Math-Run-Function, use only one of (automatically done :=) 00101 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00102 // "OneSrc" Prototype 00103 static gboolean shiftarea_run( Scan *Src, Scan *Dest ); 00104 #else 00105 // "TwoSrc" Prototype 00106 static gboolean shiftarea_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00107 #endif 00108 00109 // Fill in the GxsmPlugin Description here 00110 GxsmPlugin shiftarea_pi = { 00111 NULL, // filled in and used by Gxsm, don't touch ! 00112 NULL, // filled in and used by Gxsm, don't touch ! 00113 0, // filled in and used by Gxsm, don't touch ! 00114 NULL, // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 00115 // filled in here by Gxsm on Plugin load, 00116 // just after init() is called !!! 00117 // ---------------------------------------------------------------------- 00118 // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc 00119 "shiftarea-" 00120 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00121 "M1S" 00122 #else 00123 "M2S" 00124 #endif 00125 "-TR", 00126 // Plugin's Category - used to autodecide on Pluginloading or ignoring 00127 // NULL: load, else 00128 // example: "+noHARD +STM +AFM" 00129 // load only, if "+noHARD: no hardware" and Instrument is STM or AFM 00130 // +/-xxxHARD und (+/-INST or ...) 00131 NULL, 00132 // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details) 00133 "Shift area does this and that.", 00134 // Author(s) 00135 "stefan", 00136 // Menupath to position where it is appendet to 00137 N_("_Math/_Transformations/"), 00138 // Menuentry 00139 N_("Shift-Area"), 00140 // help text shown on menu 00141 N_("Shift area does this and that."), 00142 // more info... 00143 "The Shift-Area Plugin works with the line-object.\n It can connect to shifted areas", 00144 NULL, // error msg, plugin may put error status msg here later 00145 NULL, // Plugin Status, managed by Gxsm, plugin may manipulate it too 00146 // init-function pointer, can be "NULL", 00147 // called if present at plugin load 00148 shiftarea_init, 00149 // query-function pointer, can be "NULL", 00150 // called if present after plugin init to let plugin manage it install itself 00151 NULL, // query should be "NULL" for Gxsm-Math-Plugin !!! 00152 // about-function, can be "NULL" 00153 // can be called by "Plugin Details" 00154 shiftarea_about, 00155 // configure-function, can be "NULL" 00156 // can be called by "Plugin Details" 00157 shiftarea_configure, 00158 // run-function, can be "NULL", if non-Zero and no query defined, 00159 // it is called on menupath->"plugin" 00160 NULL, // run should be "NULL" for Gxsm-Math-Plugin !!! 00161 // cleanup-function, can be "NULL" 00162 // called if present at plugin removeal 00163 shiftarea_cleanup 00164 }; 00165 00166 // special math Plugin-Strucure, use 00167 // GxsmMathOneSrcPlugin shiftarea_m1s_pi -> "OneSrcMath" 00168 // GxsmMathTwoSrcPlugin shiftarea_m2s_pi -> "TwoSrcMath" 00169 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00170 GxsmMathOneSrcPlugin shiftarea_m1s_pi 00171 #else 00172 GxsmMathTwoSrcPlugin shiftarea_m2s_pi 00173 #endif 00174 = { 00175 // math-function to run, see prototype(s) above!! 00176 shiftarea_run 00177 }; 00178 00179 // Text used in Aboutbox, please update!! 00180 static const char *about_text = N_("Gxsm shiftarea Plugin\n\n" 00181 "Shift area with line object."); 00182 00183 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 00184 // Essential Plugin Function!! 00185 GxsmPlugin *get_gxsm_plugin_info ( void ){ 00186 shiftarea_pi.description = g_strdup_printf(N_("Gxsm MathOneArg shiftarea plugin %s"), VERSION); 00187 return &shiftarea_pi; 00188 } 00189 00190 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 00191 // used to find out which Math Type the Plugin is!! 00192 // Essential Plugin Function!! 00193 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00194 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 00195 return &shiftarea_m1s_pi; 00196 } 00197 #else 00198 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00199 return &shiftarea_m2s_pi; 00200 } 00201 #endif 00202 00203 /* Here we go... */ 00204 // init-Function 00205 static void shiftarea_init(void) 00206 { 00207 PI_DEBUG (DBG_L2, "shiftarea Plugin Init"); 00208 } 00209 00210 // about-Function 00211 static void shiftarea_about(void) 00212 { 00213 const gchar *authors[] = { shiftarea_pi.authors, NULL}; 00214 gtk_widget_show(gnome_about_new ( shiftarea_pi.name, 00215 VERSION, 00216 N_("(C) 2000 the Free Software Foundation"), 00217 about_text, 00218 authors, 00219 NULL, NULL, NULL 00220 )); 00221 } 00222 00223 // configure-Function 00224 static void shiftarea_configure(void) 00225 { 00226 if(shiftarea_pi.app) 00227 shiftarea_pi.app->message("shiftarea Plugin Configuration"); 00228 } 00229 00230 // cleanup-Function 00231 static void shiftarea_cleanup(void) 00232 { 00233 PI_DEBUG (DBG_L2, "shiftarea Plugin Cleanup"); 00234 } 00235 00236 // run-Function 00237 static gboolean shiftarea_run(Scan *Src, Scan *Dest) 00238 { 00239 00240 int x1, x2, top, bottom, hshift, vshift; 00241 MOUSERECT msr; 00242 MkMausSelect(Src->Pkt2d, &msr, Src->mem2d->GetNx(), Src->mem2d->GetNy()); 00243 00244 if( msr.xSize < 1 || msr.ySize < 1){ 00245 return MATH_SELECTIONERR; 00246 } 00247 else{ 00248 x1 = Src->Pkt2d[0].x; 00249 x2 = Src->Pkt2d[1].x; 00250 top = msr.yTop; 00251 bottom = msr.yBottom; 00252 } 00253 // PI_DEBUG (DBG_L2, "Plugin Shiftarea: " << x1 << " " << x2 << " " <<top << " " <<bottom << endl; 00254 00255 vshift = bottom - top; 00256 00257 if(x2>x1){ // funktioniert 00258 PI_DEBUG (DBG_L2, "x2 groesser x1 "); 00259 hshift = x2 - x1; 00260 Dest->mem2d->Resize(Dest->data.s.nx+hshift, Dest->data.s.ny); 00261 00262 double dummy; 00263 for(int line=0; line<Dest->data.s.ny; line++){ 00264 for(int col=0; col<Dest->data.s.nx+hshift; col++){ 00265 00266 if(line < top){ // obere haelfte 00267 if(col < hshift) 00268 dummy = 0; 00269 else 00270 dummy = Src->mem2d->GetDataPkt(col-hshift, line); 00271 } 00272 00273 if( line >= top) { //untere haelfte 00274 if(col >= Src->data.s.nx) 00275 dummy = 0; 00276 else 00277 dummy = Src->mem2d->GetDataPkt(col, line); 00278 } 00279 00280 Dest->mem2d->PutDataPkt(dummy, col, line); 00281 } 00282 } 00283 } 00284 else if (x1>x2){ // funktioniert 00285 hshift = x1 - x2; 00286 Dest->mem2d->Resize(Dest->data.s.nx+hshift, Dest->data.s.ny); 00287 00288 double dummy; 00289 for(int line=0; line<Dest->data.s.ny; line++){ 00290 for(int col=0; col<Dest->data.s.nx+hshift; col++){ 00291 00292 if(line >= top){ //untere haelfte 00293 if(col < hshift) 00294 dummy = 0; 00295 else 00296 dummy = Src->mem2d->GetDataPkt(col-hshift, line); 00297 } 00298 00299 if( line < top) { //obere haelfte 00300 if(col < Dest->data.s.nx) //kleiner xgrenze 00301 dummy = Src->mem2d->GetDataPkt(col, line); 00302 else //groesser xgrenze 00303 dummy = 0; 00304 } 00305 //execute 00306 Dest->mem2d->PutDataPkt(dummy, col, line); 00307 } 00308 } 00309 } 00310 return MATH_OK; 00311 } 00312