Difference between revisions of "Creating a new SPObject"

From Inkscape Wiki
Jump to navigation Jump to search
 
(add changes for c++ified SPObject)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
http://rxfarma.com/pharmacy/accolate.html
Create two new files in your source tree, sp-customobject.cpp and sp-customobject.h.
http://rxfarma.com/pharmacy/accupril.html
 
http://rxfarma.com/pharmacy/accutane.html
sp-customobject.h
http://rxfarma.com/pharmacy/acetaminophen.html
#ifndef SP_CUSTOMOBJECT_H_SEEN
http://rxfarma.com/pharmacy/acetazolamide.html
#define SP_CUSTOMOBJECT_H_SEEN
http://rxfarma.com/pharmacy/aciphex.html
http://rxfarma.com/pharmacy/actonel.html
/** \file
http://rxfarma.com/pharmacy/actos.html
  * Your custom object implementation
http://rxfarma.com/pharmacy/acyclovir.html
  *
http://rxfarma.com/pharmacy/adalat.html
  * Authors:
http://rxfarma.com/pharmacy/adapalene.html
  *  You
http://rxfarma.com/pharmacy/adderall.html
  *
http://rxfarma.com/pharmacy/adipex.html
  * Copyright (C) You 2???
http://rxfarma.com/pharmacy/advil.html
  * Released under GNU GPL, read the file 'COPYING' for more information
http://rxfarma.com/pharmacy/aerobid.html
  */
http://rxfarma.com/pharmacy/albenza.html
http://rxfarma.com/pharmacy/albuterol.html
#include "sp-object.h"
http://rxfarma.com/pharmacy/aldactone.html
http://rxfarma.com/pharmacy/aldara.html
/* Skeleton base class */
http://rxfarma.com/pharmacy/aldomet.html
http://rxfarma.com/pharmacy/alendronate.html
#define SP_CUSTOM_OBJECT(o) (dynamic_cast<SPCustomObject*>(o))
http://rxfarma.com/pharmacy/alesse.html
#define SP_IS_CUSTOM_OBJECT(o) (dynamic_cast<SPCustomObject*>(o) != NULL)
http://rxfarma.com/pharmacy/allegra.html
 
http://rxfarma.com/pharmacy/allopurinol.html
class SPCustomObject : public SPObject {
http://rxfarma.com/pharmacy/alprazolam.html
public:
http://rxfarma.com/pharmacy/altace.html
    SPCustomObject() {}
http://rxfarma.com/pharmacy/amantadine.html
    virtual ~SPCustomObject() {}
http://rxfarma.com/pharmacy/amaryl.html
http://rxfarma.com/pharmacy/ambien.html
    // to do anything useful with your new object, you need to override the following methods:
http://rxfarma.com/pharmacy/amiloride.html
    virtual void build(SPDocument * doc, Inkscape::XML::Node *repr);
http://rxfarma.com/pharmacy/amiodarone.html
    virtual void set(unsigned key, const gchar* value);
http://rxfarma.com/pharmacy/amitriptyline.html
    virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags);
http://rxfarma.com/pharmacy/amlodipine.html
};
http://rxfarma.com/pharmacy/amoxicillin.html
http://rxfarma.com/pharmacy/anabolic.html
http://rxfarma.com/pharmacy/anadrol.html
#endif /* !SP_CUSTOMOBJECT_H_SEEN */
http://rxfarma.com/pharmacy/androcur.html
 
http://rxfarma.com/pharmacy/antabuse.html
 
http://rxfarma.com/pharmacy/antivert.html
Add this code into your .cpp file, which will register your SP object with the XML tree:
http://rxfarma.com/pharmacy/arava.html
namespace {
http://rxfarma.com/pharmacy/aricept.html
    SPObject* createCustomObject() {
http://rxfarma.com/pharmacy/arimidex.html
        return new SPCustomObject();
http://rxfarma.com/pharmacy/atarax.html
    }
http://rxfarma.com/pharmacy/atenolol.html
    bool customObjectsRegistered = SPFactory::instance().registerObject("name_in_svg", createCustomObject);
http://rxfarma.com/pharmacy/ativan.html
}
http://rxfarma.com/pharmacy/atorvastatin.html
(If your SPObject doesn't have a useful XML representation, you can skip this call.)
http://rxfarma.com/pharmacy/atropine.html
 
http://rxfarma.com/pharmacy/atrovent.html
When you override build, set, or write, you need to include a call to the base class method:
http://rxfarma.com/pharmacy/augmentin.html
 
http://rxfarma.com/pharmacy/avandia.html
void
http://rxfarma.com/pharmacy/avapro.html
SPCustomObject::build(SPDocument* doc, Inkscape::XML::Node* repr) {
http://rxfarma.com/pharmacy/azathioprine.html
    // read in attributes from repr
http://rxfarma.com/pharmacy/azithromycin.html
    readAttr( "inkscape:not-an-attribute" ); // this propogates up to SPObject, which calls the virtual set() method, finally calling back here
http://rxfarma.com/pharmacy/baclofen.html
    SPObject::build(doc, repr);
http://rxfarma.com/pharmacy/bactroban.html
http://rxfarma.com/pharmacy/balanced.html
    // maybe do some more stuff here
http://rxfarma.com/pharmacy/baycol.html
}
http://rxfarma.com/pharmacy/bayer.html
 
http://rxfarma.com/pharmacy/bentyl.html
Inkscape::XML::Node*
http://rxfarma.com/pharmacy/betamethasone.html
SPCustomObject::write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags) {
http://rxfarma.com/pharmacy/betapace.html
    // write our attributes to XML
http://rxfarma.com/pharmacy/bextra.html
   
http://rxfarma.com/pharmacy/biaxin.html
    // the repr doesn't exist, we need to create it
http://rxfarma.com/pharmacy/bisoprolol.html
    if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
http://rxfarma.com/pharmacy/bontril.html
        repr = doc->createElement("name_in_svg");
http://rxfarma.com/pharmacy/botox.html
    }
http://rxfarma.com/pharmacy/bricanyl.html
http://rxfarma.com/pharmacy/budesonide.html
    if (flags & SP_OBJECT_WRITE_EXT) {
http://rxfarma.com/pharmacy/buprenex.html
        // write Inkscape-only objects here, not copied to plain SVG dump.
http://rxfarma.com/pharmacy/buprenorphine.html
        repr->setAttribute("inkscape:not-an-attribute");
http://rxfarma.com/pharmacy/bupropion.html
    }
http://rxfarma.com/pharmacy/buspar.html
    SPObject::write(doc, repr, flags);
http://rxfarma.com/pharmacy/buspirone.html
    // and possibly do anything else here
http://rxfarma.com/pharmacy/butalbital.html
    return repr;
http://rxfarma.com/pharmacy/caffeine.html
}
http://rxfarma.com/pharmacy/calan.html
 
http://rxfarma.com/pharmacy/calcium.html
void
http://rxfarma.com/pharmacy/candida.html
SPCustomObject::set(unsigned int key, gchar const* value) {
http://rxfarma.com/pharmacy/capoten.html
    // set an object from its value
http://rxfarma.com/pharmacy/captopril.html
    switch (key) {
http://rxfarma.com/pharmacy/carbamazepine.html
        case SP_ATTR_INKSCAPE_CUSTOM:
http://rxfarma.com/pharmacy/carbidopa.html
            if ((value && *value) && !strcmp(value, "true")) {
http://rxfarma.com/pharmacy/cardura.html
                val = true;
http://rxfarma.com/pharmacy/carisoprodol.html
            }
http://rxfarma.com/pharmacy/carvedilol.html
            break;
http://rxfarma.com/pharmacy/casodex.html
        default:
http://rxfarma.com/pharmacy/cataflam.html
            SPObject::set(key, value);
http://rxfarma.com/pharmacy/catapres.html
            break;
http://rxfarma.com/pharmacy/ceclor.html
    }
http://rxfarma.com/pharmacy/collagen.html
}
http://rxfarma.com/pharmacy/compazine.html
http://rxfarma.com/pharmacy/condylox.html
http://rxfarma.com/pharmacy/cordarone.html
http://rxfarma.com/pharmacy/coreg.html
http://rxfarma.com/pharmacy/cortaid.html
http://rxfarma.com/pharmacy/coumadin.html
http://rxfarma.com/pharmacy/cozaar.html
http://rxfarma.com/pharmacy/crystal.html
http://rxfarma.com/pharmacy/cutivate.html
http://rxfarma.com/pharmacy/cyclobenzaprine.html
http://rxfarma.com/pharmacy/cyclosporine.html
http://rxfarma.com/pharmacy/cytotec.html
http://rxfarma.com/pharmacy/darvon.html
http://rxfarma.com/pharmacy/denavir.html
http://rxfarma.com/pharmacy/depakene.html
http://rxfarma.com/pharmacy/depakote.html
http://rxfarma.com/pharmacy/desogen.html
http://rxfarma.com/pharmacy/desowen.html
http://rxfarma.com/pharmacy/desyrel.html
http://rxfarma.com/pharmacy/detrol.html
http://rxfarma.com/pharmacy/dexamethasone.html
http://rxfarma.com/pharmacy/diabeta.html
http://rxfarma.com/pharmacy/diabinese.html
http://rxfarma.com/pharmacy/diamox.html
http://rxfarma.com/pharmacy/diarrhea.html
http://rxfarma.com/pharmacy/diazepam.html
http://rxfarma.com/pharmacy/diclofenac.html
http://rxfarma.com/pharmacy/didrex.html
http://rxfarma.com/pharmacy/diethylpropion.html
http://rxfarma.com/pharmacy/differin.html
http://rxfarma.com/pharmacy/diflucan.html
http://rxfarma.com/pharmacy/dilantin.html
http://rxfarma.com/pharmacy/dilaudid.html
http://rxfarma.com/pharmacy/diltiazem.html
http://rxfarma.com/pharmacy/diovan.html
http://rxfarma.com/pharmacy/diprolene.html
http://rxfarma.com/pharmacy/ditropan.html
http://rxfarma.com/pharmacy/divalproex.html
http://rxfarma.com/pharmacy/donepezil.html
http://rxfarma.com/pharmacy/dopamine.html
http://rxfarma.com/pharmacy/doryx.html
http://rxfarma.com/pharmacy/dostinex.html
http://rxfarma.com/pharmacy/dovonex.html
http://rxfarma.com/pharmacy/doxazosin.html
http://rxfarma.com/pharmacy/doxycycline.html
http://rxfarma.com/pharmacy/echinacea.html
http://rxfarma.com/pharmacy/effexor.html
http://rxfarma.com/pharmacy/elavil.html
http://rxfarma.com/pharmacy/elidel.html
http://rxfarma.com/pharmacy/elimite.html
http://rxfarma.com/pharmacy/elocon.html
http://rxfarma.com/pharmacy/eltroxin.html
http://rxfarma.com/pharmacy/enalapril.html
http://rxfarma.com/pharmacy/ephedrine.html
http://rxfarma.com/pharmacy/epival.html
http://rxfarma.com/pharmacy/epivir.html
http://rxfarma.com/pharmacy/erythromycin.html
http://rxfarma.com/pharmacy/escitalopram.html
http://rxfarma.com/pharmacy/esomeprazole.html
http://rxfarma.com/pharmacy/estradiol.html
http://rxfarma.com/pharmacy/estrogens.html
http://rxfarma.com/pharmacy/eulexin.html
http://rxfarma.com/pharmacy/eurax.html
http://rxfarma.com/pharmacy/evista.html
http://rxfarma.com/pharmacy/excedrin.html
http://rxfarma.com/pharmacy/exelon.html
http://rxfarma.com/pharmacy/factor.html
http://rxfarma.com/pharmacy/famotidine.html
http://rxfarma.com/pharmacy/famvir.html
http://rxfarma.com/pharmacy/fastin.html
http://rxfarma.com/pharmacy/feldene.html
http://rxfarma.com/pharmacy/felodipine.html
http://rxfarma.com/pharmacy/femara.html
http://rxfarma.com/pharmacy/fexofenadine.html
http://rxfarma.com/pharmacy/finasteride.html
http://rxfarma.com/pharmacy/flagyl.html
http://rxfarma.com/pharmacy/flexeril.html
http://rxfarma.com/pharmacy/flomax.html
http://rxfarma.com/pharmacy/flonase.html
http://rxfarma.com/pharmacy/florinef.html
http://rxfarma.com/pharmacy/flovent.html
http://rxfarma.com/pharmacy/floxin.html
http://rxfarma.com/pharmacy/fluconazole.html
http://rxfarma.com/pharmacy/fluoxetine.html
http://rxfarma.com/pharmacy/flutamide.html
http://rxfarma.com/pharmacy/fluticasone.html
http://rxfarma.com/pharmacy/fluvastatin.html
http://rxfarma.com/pharmacy/fluvoxamine.html
http://rxfarma.com/pharmacy/fosamax.html
http://rxfarma.com/pharmacy/furosemide.html
http://rxfarma.com/pharmacy/gabapentin.html
http://rxfarma.com/pharmacy/gemfibrozil.html
http://rxfarma.com/pharmacy/glipizide.html
http://rxfarma.com/pharmacy/glucophage.html
http://rxfarma.com/pharmacy/glucosamine.html
http://rxfarma.com/pharmacy/glucotrol.html
http://rxfarma.com/pharmacy/glutathione.html
http://rxfarma.com/pharmacy/glyburide.html
http://rxfarma.com/pharmacy/haldol.html
http://rxfarma.com/pharmacy/humulin.html
http://rxfarma.com/pharmacy/hydrea.html
http://rxfarma.com/pharmacy/hydrochlorothiazide.html
http://rxfarma.com/pharmacy/hydrocodone.html
http://rxfarma.com/pharmacy/hydrocortisone.html
http://rxfarma.com/pharmacy/hydromorphone.html
http://rxfarma.com/pharmacy/hydroxyzine.html
http://rxfarma.com/pharmacy/hyzaar.html
http://rxfarma.com/pharmacy/ibuprofen.html
http://rxfarma.com/pharmacy/imipramine.html
http://rxfarma.com/pharmacy/imitrex.html
http://rxfarma.com/pharmacy/immune.html
http://rxfarma.com/pharmacy/imodium.html
http://rxfarma.com/pharmacy/imuran.html
http://rxfarma.com/pharmacy/indapamide.html
http://rxfarma.com/pharmacy/inderal.html
http://rxfarma.com/pharmacy/indocin.html
http://rxfarma.com/pharmacy/inositol.html
http://rxfarma.com/pharmacy/insulin.html
http://rxfarma.com/pharmacy/interferon.html
http://rxfarma.com/pharmacy/ionamin.html
http://rxfarma.com/pharmacy/isoniazid.html
http://rxfarma.com/pharmacy/isoptin.html
http://rxfarma.com/pharmacy/isotretinoin.html
http://rxfarma.com/pharmacy/itraconazole.html
http://rxfarma.com/pharmacy/keflex.html
http://rxfarma.com/pharmacy/ketoconazole.html
http://rxfarma.com/pharmacy/ketoprofen.html
http://rxfarma.com/pharmacy/ketotifen.html
http://rxfarma.com/pharmacy/klonopin.html
http://rxfarma.com/pharmacy/lactulose.html
http://rxfarma.com/pharmacy/lamictal.html
http://rxfarma.com/pharmacy/lamisil.html
http://rxfarma.com/pharmacy/lamivudine.html
http://rxfarma.com/pharmacy/lamotrigine.html
http://rxfarma.com/pharmacy/lanoxin.html
http://rxfarma.com/pharmacy/lansoprazole.html
http://rxfarma.com/pharmacy/lasix.html
http://rxfarma.com/pharmacy/lescol.html
http://rxfarma.com/pharmacy/letrozole.html
http://rxfarma.com/pharmacy/levaquin.html
http://rxfarma.com/pharmacy/levitra.html
http://rxfarma.com/pharmacy/levodopa.html
http://rxfarma.com/pharmacy/levofloxacin.html
http://rxfarma.com/pharmacy/levothyroxine.html
http://rxfarma.com/pharmacy/lexapro.html
http://rxfarma.com/pharmacy/lindane.html
http://rxfarma.com/pharmacy/lipitor.html
http://rxfarma.com/pharmacy/lisinopril.html
http://rxfarma.com/pharmacy/lithium.html
http://rxfarma.com/pharmacy/locoid.html
http://rxfarma.com/pharmacy/lopid.html
http://rxfarma.com/pharmacy/lopressor.html
http://rxfarma.com/pharmacy/loprox.html
http://rxfarma.com/pharmacy/lorazepam.html
http://rxfarma.com/pharmacy/losartan.html
http://rxfarma.com/pharmacy/lotensin.html
http://rxfarma.com/pharmacy/lotrimin.html
http://rxfarma.com/pharmacy/lovastatin.html
http://rxfarma.com/pharmacy/luvox.html
http://rxfarma.com/pharmacy/lysodren.html
http://rxfarma.com/pharmacy/macrodantin.html
http://rxfarma.com/pharmacy/medrol.html
http://rxfarma.com/pharmacy/megace.html
http://rxfarma.com/pharmacy/melatonin.html
http://rxfarma.com/pharmacy/meridia.html
http://rxfarma.com/pharmacy/mesalamine.html
http://rxfarma.com/pharmacy/mestinon.html
http://rxfarma.com/pharmacy/metaxalone.html
http://rxfarma.com/pharmacy/metformin.html
http://rxfarma.com/pharmacy/metoclopramide.html
http://rxfarma.com/pharmacy/metoprolol.html
http://rxfarma.com/pharmacy/metrogel.html
http://rxfarma.com/pharmacy/metronidazole.html
http://rxfarma.com/pharmacy/mevacor.html
http://rxfarma.com/pharmacy/micardis.html
http://rxfarma.com/pharmacy/miconazole.html
http://rxfarma.com/pharmacy/micronor.html
http://rxfarma.com/pharmacy/midazolam.html
http://rxfarma.com/pharmacy/minipress.html
http://rxfarma.com/pharmacy/minocin.html
http://rxfarma.com/pharmacy/minocycline.html
http://rxfarma.com/pharmacy/minoxidil.html
http://rxfarma.com/pharmacy/mircette.html
http://rxfarma.com/pharmacy/mometasone.html
http://rxfarma.com/pharmacy/montelukast.html
http://rxfarma.com/pharmacy/morphine.html
http://rxfarma.com/pharmacy/motrin.html
http://rxfarma.com/pharmacy/mycostatin.html
http://rxfarma.com/pharmacy/nabumetone.html
http://rxfarma.com/pharmacy/nadolol.html
http://rxfarma.com/pharmacy/naltrexone.html
http://rxfarma.com/pharmacy/naprosyn.html
http://rxfarma.com/pharmacy/naproxen.html
http://rxfarma.com/pharmacy/nasacort.html
http://rxfarma.com/pharmacy/nattokinase.html
http://rxfarma.com/pharmacy/neurontin.html
http://rxfarma.com/pharmacy/nexium.html
http://rxfarma.com/pharmacy/nifedipine.html
http://rxfarma.com/pharmacy/nizoral.html
http://rxfarma.com/pharmacy/nolvadex.html
http://rxfarma.com/pharmacy/norflex.html
http://rxfarma.com/pharmacy/nortriptyline.html
http://rxfarma.com/pharmacy/norvasc.html
http://rxfarma.com/pharmacy/nystatin.html
http://rxfarma.com/pharmacy/olanzapine.html
http://rxfarma.com/pharmacy/omeprazole.html
http://rxfarma.com/pharmacy/orlistat.html
http://rxfarma.com/pharmacy/ortho.html
http://rxfarma.com/pharmacy/orudis.html
http://rxfarma.com/pharmacy/oseltamivir.html
http://rxfarma.com/pharmacy/oxycodone.html
http://rxfarma.com/pharmacy/paroxetine.html
http://rxfarma.com/pharmacy/patanol.html
http://rxfarma.com/pharmacy/paxil.html
http://rxfarma.com/pharmacy/penicillin.html
http://rxfarma.com/pharmacy/penlac.html
http://rxfarma.com/pharmacy/pepcid.html
http://rxfarma.com/pharmacy/permethrin.html
http://rxfarma.com/pharmacy/phendimetrazine.html
http://rxfarma.com/pharmacy/phentermine.html
http://rxfarma.com/pharmacy/pioglitazone.html
http://rxfarma.com/pharmacy/piroxicam.html
http://rxfarma.com/pharmacy/plaquenil.html
http://rxfarma.com/pharmacy/plavix.html
http://rxfarma.com/pharmacy/plendil.html
http://rxfarma.com/pharmacy/polyethylene.html
http://rxfarma.com/pharmacy/potassium.html
http://rxfarma.com/pharmacy/pravachol.html
http://rxfarma.com/pharmacy/prednisolone.html
http://rxfarma.com/pharmacy/prednisone.html
http://rxfarma.com/pharmacy/premarin.html
http://rxfarma.com/pharmacy/prenatal.html
http://rxfarma.com/pharmacy/prevacid.html
http://rxfarma.com/pharmacy/primatene.html
http://rxfarma.com/pharmacy/prinivil.html
http://rxfarma.com/pharmacy/procardia.html
http://rxfarma.com/pharmacy/prochlorperazine.html
http://rxfarma.com/pharmacy/progesterone.html
http://rxfarma.com/pharmacy/promethazine.html
http://rxfarma.com/pharmacy/prometrium.html
http://rxfarma.com/pharmacy/propafenone.html
http://rxfarma.com/pharmacy/propecia.html
http://rxfarma.com/pharmacy/propoxyphene.html
http://rxfarma.com/pharmacy/propranolol.html
http://rxfarma.com/pharmacy/propulsid.html
http://rxfarma.com/pharmacy/protonix.html
http://rxfarma.com/pharmacy/protopic.html
http://rxfarma.com/pharmacy/proventil.html
http://rxfarma.com/pharmacy/provera.html
http://rxfarma.com/pharmacy/provigil.html
http://rxfarma.com/pharmacy/prozac.html
http://rxfarma.com/pharmacy/pseudoephedrine.html
http://rxfarma.com/pharmacy/pulmicort.html
http://rxfarma.com/pharmacy/pycnogenol.html
http://rxfarma.com/pharmacy/pyrethrins.html
http://rxfarma.com/pharmacy/pyridium.html
http://rxfarma.com/pharmacy/quinine.html
http://rxfarma.com/pharmacy/rabeprazole.html
http://rxfarma.com/pharmacy/raloxifene.html
http://rxfarma.com/pharmacy/ramipril.html
http://rxfarma.com/pharmacy/ranitidine.html
http://rxfarma.com/pharmacy/reglan.html
http://rxfarma.com/pharmacy/relafen.html
http://rxfarma.com/pharmacy/remeron.html
http://rxfarma.com/pharmacy/renova.html
http://rxfarma.com/pharmacy/replacement.html
http://rxfarma.com/pharmacy/restoril.html
http://rxfarma.com/pharmacy/retrovir.html
http://rxfarma.com/pharmacy/rhinocort.html
http://rxfarma.com/pharmacy/risperdal.html
http://rxfarma.com/pharmacy/ritalin.html
http://rxfarma.com/pharmacy/rivastigmine.html
http://rxfarma.com/pharmacy/rivotril.html
http://rxfarma.com/pharmacy/robitussin.html
http://rxfarma.com/pharmacy/rofecoxib.html
http://rxfarma.com/pharmacy/rogaine.html
http://rxfarma.com/pharmacy/rosiglitazone.html
http://rxfarma.com/pharmacy/roxicodone.html
http://rxfarma.com/pharmacy/rythmol.html
http://rxfarma.com/pharmacy/salbutamol.html
http://rxfarma.com/pharmacy/salmeterol.html
http://rxfarma.com/pharmacy/sarafem.html
http://rxfarma.com/pharmacy/selegiline.html
http://rxfarma.com/pharmacy/selenium.html
http://rxfarma.com/pharmacy/seretide.html
http://rxfarma.com/pharmacy/serevent.html
http://rxfarma.com/pharmacy/serophene.html
http://rxfarma.com/pharmacy/seroquel.html
http://rxfarma.com/pharmacy/sertraline.html
http://rxfarma.com/pharmacy/sibutramine.html
http://rxfarma.com/pharmacy/sildenafil.html
http://rxfarma.com/pharmacy/simvastatin.html
http://rxfarma.com/pharmacy/singulair.html
http://rxfarma.com/pharmacy/skelaxin.html
http://rxfarma.com/pharmacy/solution.html
http://rxfarma.com/pharmacy/sonata.html
http://rxfarma.com/pharmacy/sotalol.html
http://rxfarma.com/pharmacy/spironolactone.html
http://rxfarma.com/pharmacy/sporanox.html
http://rxfarma.com/pharmacy/stadol.html
http://rxfarma.com/pharmacy/starlix.html
http://rxfarma.com/pharmacy/steroids.html
http://rxfarma.com/pharmacy/stimate.html
http://rxfarma.com/pharmacy/strattera.html
http://rxfarma.com/pharmacy/sucralfate.html
http://rxfarma.com/pharmacy/sumatriptan.html
http://rxfarma.com/pharmacy/surmontil.html
http://rxfarma.com/pharmacy/symmetrel.html
http://rxfarma.com/pharmacy/synalar.html
http://rxfarma.com/pharmacy/synephrine.html
http://rxfarma.com/pharmacy/synthroid.html
http://rxfarma.com/pharmacy/tadalafil.html
http://rxfarma.com/pharmacy/tambocor.html
http://rxfarma.com/pharmacy/tamiflu.html
http://rxfarma.com/pharmacy/tamoxifen.html
http://rxfarma.com/pharmacy/tamsulosin.html
http://rxfarma.com/pharmacy/tapazole.html
http://rxfarma.com/pharmacy/temazepam.html
http://rxfarma.com/pharmacy/temovate.html
http://rxfarma.com/pharmacy/tenoretic.html
http://rxfarma.com/pharmacy/tenuate.html
http://rxfarma.com/pharmacy/terazosin.html
http://rxfarma.com/pharmacy/terbinafine.html
http://rxfarma.com/pharmacy/terbutaline.html
http://rxfarma.com/pharmacy/terramycin.html
http://rxfarma.com/pharmacy/testosterone.html
http://rxfarma.com/pharmacy/tetracycline.html
http://rxfarma.com/pharmacy/theophylline.html
http://rxfarma.com/pharmacy/therapy.html
http://rxfarma.com/pharmacy/thorazine.html
http://rxfarma.com/pharmacy/thyroid.html
http://rxfarma.com/pharmacy/tibolone.html
http://rxfarma.com/pharmacy/ticlopidine.html
http://rxfarma.com/pharmacy/timolol.html
http://rxfarma.com/pharmacy/tizanidine.html
http://rxfarma.com/pharmacy/topamax.html
http://rxfarma.com/pharmacy/topiramate.html
http://rxfarma.com/pharmacy/toprol.html
http://rxfarma.com/pharmacy/toradol.html
http://rxfarma.com/pharmacy/tramadol.html
http://rxfarma.com/pharmacy/transderm.html
http://rxfarma.com/pharmacy/trazodone.html
http://rxfarma.com/pharmacy/tretinoin.html
http://rxfarma.com/pharmacy/tricor.html
http://rxfarma.com/pharmacy/trimipramine.html
http://rxfarma.com/pharmacy/trimox.html
http://rxfarma.com/pharmacy/tylenol.html
http://rxfarma.com/pharmacy/ultracet.html
http://rxfarma.com/pharmacy/unisom.html
http://rxfarma.com/pharmacy/urecholine.html
http://rxfarma.com/pharmacy/valacyclovir.html
http://rxfarma.com/pharmacy/valdecoxib.html
http://rxfarma.com/pharmacy/valium.html
http://rxfarma.com/pharmacy/valsartan.html
http://rxfarma.com/pharmacy/valtrex.html
http://rxfarma.com/pharmacy/vardenafil.html
http://rxfarma.com/pharmacy/vasotec.html
http://rxfarma.com/pharmacy/vitamins.html
http://rxfarma.com

Latest revision as of 20:40, 14 May 2014

Create two new files in your source tree, sp-customobject.cpp and sp-customobject.h.

sp-customobject.h

#ifndef SP_CUSTOMOBJECT_H_SEEN
#define SP_CUSTOMOBJECT_H_SEEN

/** \file
 * Your custom object implementation
 * 
 * Authors:
 *   You
 *
 * Copyright (C) You 2???
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include "sp-object.h"

/* Skeleton base class */

#define SP_CUSTOM_OBJECT(o) (dynamic_cast<SPCustomObject*>(o))
#define SP_IS_CUSTOM_OBJECT(o) (dynamic_cast<SPCustomObject*>(o) != NULL)
 
class SPCustomObject : public SPObject {
public:
    SPCustomObject() {}
    virtual ~SPCustomObject() {}

    // to do anything useful with your new object, you need to override the following methods:
    virtual void build(SPDocument * doc, Inkscape::XML::Node *repr);
    virtual void set(unsigned key, const gchar* value);
    virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags);
};


#endif /* !SP_CUSTOMOBJECT_H_SEEN */


Add this code into your .cpp file, which will register your SP object with the XML tree:

namespace {
    SPObject* createCustomObject() {
        return new SPCustomObject();
    }
    bool customObjectsRegistered = SPFactory::instance().registerObject("name_in_svg", createCustomObject);
}

(If your SPObject doesn't have a useful XML representation, you can skip this call.)

When you override build, set, or write, you need to include a call to the base class method:

void
SPCustomObject::build(SPDocument* doc, Inkscape::XML::Node* repr) {
    // read in attributes from repr
    readAttr( "inkscape:not-an-attribute" ); // this propogates up to SPObject, which calls the virtual set() method, finally calling back here
    SPObject::build(doc, repr);

    // maybe do some more stuff here
}
Inkscape::XML::Node*
SPCustomObject::write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags) {
    // write our attributes to XML
    
    // the repr doesn't exist, we need to create it
    if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
        repr = doc->createElement("name_in_svg");
    }

    if (flags & SP_OBJECT_WRITE_EXT) {
        // write Inkscape-only objects here, not copied to plain SVG dump.
        repr->setAttribute("inkscape:not-an-attribute");
    }
    SPObject::write(doc, repr, flags);
    // and possibly do anything else here
    return repr;
}
void
SPCustomObject::set(unsigned int key, gchar const* value) {
    // set an object from its value
    switch (key) {
        case SP_ATTR_INKSCAPE_CUSTOM:
            if ((value && *value) && !strcmp(value, "true")) {
                val = true;
            }
            break;
        default:
            SPObject::set(key, value);
            break;
    }
}