glycoinfo / GlycanBuilder2

7 stars 5 forks source link

Export image: can not select any glycan #39

Open e15d5605 opened 2 years ago

e15d5605 commented 2 years ago

I try to export selecting second glycan on the canvas.

However, three glycans are visualized in the SVG file.

e15d5605 commented 2 years ago

GlycanBuilderonExportToのSVGUtilsで画像の生成を行なっている。

// esporta il documento su file
if( theDoc.isSequenceFormat(format) ) {
    if( theDoc.exportTo(filename,format) )
        setLastExportedFile(filename);
    return true;
    }
    else if( SVGUtils.export((GlycanRendererAWT) theWorkspace.getGlycanRenderer(),filename,theDoc.getStructures(),theWorkspace.getGraphicOptions().SHOW_MASSES,theWorkspace.getGraphicOptions().SHOW_REDEND,format) ) {
        setLastExportedFile(filename);
        return true;
    }
} 

SVGUtilsexportでユーザーが選択した画像形式の変換を行う。exportは複数の同名の関数を経るがここでは省略する。\

static public void export(OutputStream os, GlycanRendererAWT gr, Collection<Glycan> structures, boolean show_masses, boolean show_redend, double scale, String format,PositionManager posManager,BBoxManager bboxManager) throws Exception {
    if( format.equals("svg") )
        os.write(getVectorGraphics(gr,structures,show_masses,show_redend).getBytes());
    else if( format.equals("pdf") )        
        os.write(getPDFGraphics(gr,structures,show_masses,show_redend));
    else if( format.equals("ps") )        
        os.write(getPSGraphics(gr,structures,show_masses,show_redend));
    else if( format.equals("eps") )
        os.write(getEPSGraphics(gr,structures,show_masses,show_redend));
    else if( format.equals("bmp") || format.equals("png") || format.equals("jpg") )        
        javax.imageio.ImageIO.write(gr.getImage(structures,true,show_masses,show_redend,scale,posManager,bboxManager),format,os);
    else
        throw new Exception("Unrecognized graphic format: " + format);    
    }

GlycanBuilderのonExportToの時点で引数のGlycantheDoc.getStructures()から参照している。この関数の戻り値はキャンバスに描画されている全てのGlycanオブジェクトであるため、ユーザーが画像を生成した糖鎖をキャンバスで選択しても一切考慮されない。\ ユーザーがキャンバスから一つまたは複数の糖鎖を選択して画像を生成する機能を実現する場合は、theDoc.getStructures()から直接キャンバス上に描画されている糖鎖を取得するのではなく、ユーザーが選択した糖鎖を含んだ配列型の変数を生成し、exportの引数として利用する方法を考えられる。\ GlycanBuilderではCanvasのtheCanvasやBuilderWorkspaceのtheWorkSpace、GlycanDocumentのtheDocといったキャンバスに関連したクラスは揃えているため、ユーザーの選択している糖鎖や単糖などの選出は困難ではない。