home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-17 | 68.7 KB | 2,813 lines | [TEXT/R*ch] |
- // DSeqDoc.cp
-
- #define MASKS 1
-
- #include "DSeqDoc.h"
- #include <ncbi.h>
- #include <dgg.h>
- #include <Dvibrant.h>
- #include <DApplication.h>
- #include <DClipboard.h>
- #include <DControl.h>
- #include <DWindow.h>
- #include <DRichViewNu.h>
- #include <DTableView.h>
- #include <DViewCentral.h>
- #include <DTask.h>
- #include <DTracker.h>
- #include <DMenu.h>
- #include <DUtil.h>
- #include <DFindDlog.h>
- #include "DSeqFile.h"
- #include "DSeqEd.h"
- #include "DSeqMail.h"
- #include "DSeqCmds.h"
- #include "DSeqChildApp.h"
- #include "DSeqPrint.h"
- #include "DSeqPict.h"
-
-
-
-
-
-
- Global char* gDefSeqName = NULL;
- static char gDefSeqNameStore[128];
- Boolean DSeqDoc::fgTestSeqFile = false; // turn on/off seq-test for OpenDocument()
- Boolean DSeqDoc::fgStartDoc = true;
- Boolean DSeqDoc::fgUseColor = false;
- Boolean DSeqDoc::fgLockText = false;
- short DSeqDoc::fgViewMode = DAlnView::kModeSlide;
- Nlm_RecT DSeqDoc::fgWinRect = { 0, 0, 0, 0 };
-
- Local short gAlnCharWidth = 12;
- Local short gAlnCharHeight = 15;
- //Local short gMinCommonPercent = 0;
- Local Boolean gSwapBackground = false;
-
-
- #define ETEXT 1
-
- #define DAlnTextClass DTextLine
- // Nlm_TextLine > DTextLine -- new variant of DHiddenText
- // DEditText or DHiddenText ?? -- EditText has box around, HiddenText no box
- // DDialogScrollText( id, itsSuperior, width, height, gSeqFont, false) // true==wrap
- // DTextInScroller(long id, DView* itsSuperior, short width, short height,
- // Nlm_FonT font, Boolean wrap);
-
- extern "C" void Nlm_HScrollText (Nlm_BaR sb, Nlm_GraphiC t,
- Nlm_Int2 newval, Nlm_Int2 oldval);
- extern "C" void Nlm_DoActivate(void* g, Nlm_Boolean saveport);
- //extern Nlm_Boolean gDialogTextMultiline;
-
- //fEditSeq
- class DAlnSequence : public DAlnTextClass, public DKeyCallback
- {
- public:
- DSequence* fSeq;
- Boolean fVisible;
-
- DAlnSequence(long id, DView* itsSuperior):
- DAlnTextClass(id, itsSuperior, NULL, 1, gSeqFont), // DHiddenText
- //DAlnTextClass(id, itsSuperior, 1, 1, gSeqFont, false), // DDialogScrollText
- fSeq(NULL),fVisible(false)
- {
- SetMultilineText(false);
- }
- virtual void Scroll(Boolean vertical, DView* scrollee, short newval, short oldval);
- virtual void ShowEdit();
- virtual void HideEdit();
- virtual void ProcessKey( char c);
- virtual void selectAction();
- virtual void deselectAction();
- };
-
- void DAlnSequence::Scroll(Boolean vertical, DView* scrollee, short newval, short oldval)
- {
- if (fVisible && !vertical) {
- Nlm_HScrollText( NULL, (Nlm_GraphiC)GetNlmObject(), newval, oldval);
- }
- }
-
- void DAlnSequence::ShowEdit()
- {
- if (fSeq) SetText( fSeq->Bases());
- if (!fVisible) {
- fVisible= true;
- Show();
- Enable();
- }
- // may need this for MSWIN
- //Nlm_DoActivate(GetNlmObject(),false);
- }
-
- void DAlnSequence::HideEdit()
- {
- if (fVisible) {
- fVisible= false;
- Disable();
- Hide();
- }
- }
-
- void DAlnSequence::selectAction()
- {
- DAlnTextClass::selectAction();
- //gCursor->ibeam();
- SetKeyHandler(this); //?? also need this call in a window activate/deactivate method??
- }
-
- void DAlnSequence::deselectAction()
- {
- SetKeyHandler(NULL); //?? also need this call in a window activate/deactivate method??
- //fDoc->SetEditText(NULL);
- //gCursor->arrow();
- DAlnTextClass::deselectAction();
- }
-
- void DAlnSequence::ProcessKey( char c)
- {
- enum moves {
- down1 = 1,
- up1 = -1,
- downPage= 10, // this is arbitrary...
- upPage = -10,
- toBottom= 25000,
- toTop = -25000
- };
-
- if ( IsEnabled()) {
- // dang vibrant doens't have means to change this key, and default handlers still get
- // a crack at it...
-
- switch (c) {
-
- #if 0
- case chTab:
- //? do horizontal shift here ?
- break;
-
- case chRight:
- if (gKeys->shift()) ;
- else ;
- case chLeft:
- if (gKeys->shift()) ;
- else ;
-
- case chUp:
- if (gKeys->shift()) vertMove(toTop);
- else vertMove(up1);
- break;
-
- case chDown:
- case chEnter:
- case chReturn:
- if (gKeys->shift()) vertMove(toBottom);
- else vertMove(down1);
- break;
-
- case chPageDown : vertMove( downPage); break;
- case chPageUp : vertMove( upPage); break;
- case chHome : vertMove( toTop); break;
- case chEnd : vertMove( toBottom); break;
- #endif
-
- default:
- if (!fSeq->GoodChar(c)) Nlm_Beep();
- break;
- }
- }
- }
-
-
-
-
-
- class DMaskSelector : public DTabSelector
- {
- public:
- enum { cMaskSelector = 20732 };
- short fMaskLevel;
- DSeqList* fSeqList;
-
- DMaskSelector( DTableView* itsTable, short masklevel, DSeqList* seqlist) :
- DTabSelector( itsTable),
- fSeqList( seqlist), fMaskLevel(masklevel)
- {
- fNumber= cMaskSelector;
- }
- virtual void DoItWork();
- };
-
-
- void DMaskSelector::DoItWork()
- {
- if (fMovedOnce || fDoExtend) {
- #if MASKS
- // select masks... instead of, or as well as, table sel rect??
- if (fMaskLevel>0) {
- short row, col, top, bot, left, right;
- Nlm_RecT viewr;
- top= fNewSelection.top;
- bot= fNewSelection.bottom;
- left= fNewSelection.left;
- right= fNewSelection.right;
- for (row= top; row<bot; row++) {
- DSequence* sq= fSeqList->SeqAt(row);
- if (sq) {
- for (col= left; col<right; col++)
- if (fDoExtend) sq->SetMaskAt(col,fMaskLevel);
- else sq->FlipMaskAt(col, fMaskLevel);
- }
- }
- ((DTableView*)fView)->GetCellRect(fNewSelection,viewr);
- ((DTableView*)fView)->InvalRect( viewr);
- }
- else
- #endif
- ((DTableView*)fView)->SelectCells( fNewSelection,
- fDoExtend, DTableView::kHighlight, DTableView::kSelect);
- }
- }
-
-
-
-
- //class DAlnView : public DTableView
-
- // test var for fEditSeq bomb...
- DAlnView* gLastEditView = NULL;
-
-
- DAlnView::DAlnView( long id, DView* itsSuper, DSeqDoc* itsDocument, DSeqList* itsSeqList,
- long pixwidth, long pixheight) :
- DTableView( id, itsSuper, pixwidth, pixheight, 0, 0, Nlm_stdCharWidth, 2+Nlm_stdFontHeight,
- true, true),
- fDoc(itsDocument), fSeqList(itsSeqList), fSlider(NULL),
- fEditRow(-1), fMaskLevel(0), fCurSeq(NULL), fEditSeq(NULL),
- fLocked(false), fOwnSeqlist(false)
- {
- fKind= kindAlnView;
- gAlnCharWidth= Nlm_stdCharWidth; //Nlm_CharWidth('G');
- gAlnCharHeight= Nlm_stdLineHeight;
- this->SetResize( DView::relsuper, DView::relsuper);
- this->SetTableFont(gSeqFont);
- //fSlider= new DAlnSlider( fDoc, this, 0);
- }
-
-
- DAlnIndex::DAlnIndex( long id, DView* itsSuper, DSeqDoc* itsDocument, DSeqList* itsSeqList,
- long pixwidth, long pixheight) :
- DTableView( id, itsSuper, pixwidth, pixheight, 0, 4,
- 5*Nlm_stdCharWidth, 2+Nlm_stdFontHeight, false, true),
- fNameWidth(15),
- fSizeWidth(8),
- fKindWidth(8),
- fDoc(itsDocument),
- fSeqList(itsSeqList)
- {
- //this->SetSlateBorder(false);
- this->SetResize( DView::fixed, DView::relsuper);
- this->SetTableFont(gTextFont);
- }
-
- DAlnITitle::DAlnITitle( long id, DView* itsSuper, long pixwidth, long pixheight) :
- DTableView( id, itsSuper, pixwidth, pixheight, 1, 4,
- 5*Nlm_stdCharWidth, 2+Nlm_stdFontHeight, false, false),
- fNameWidth(15),
- fSizeWidth(8),
- fKindWidth(8)
- {
- //this->SetSlateBorder(false);
- this->SetResize( DView::fixed, DView::fixed);
- this->SetTableFont(gTextFont);
- }
-
- DAlnHIndex::DAlnHIndex( long id, DView* itsSuper, DSeqDoc* itsDocument, DSeqList* itsSeqList, long pixwidth, long pixheight) :
- DPanel( id, itsSuper, pixwidth, pixheight, DPanel::simple),
- fDoc(itsDocument),
- fSeqList(itsSeqList)
- {
- //this->SetResize( DView::matchsuper, DView::fixed);
- this->SetResize( DView::relsuper, DView::fixed);
- }
-
- DAlnView::~DAlnView()
- {
- //fSeqList= NULL; // fSeqList is owned by Doc !
- DeInstallEditSeq();
- //if (fSlider) delete fSlider;
- #if FIX_LATER
- itsEditSeq= fEditSeq;
- if (itsEditSeq && itsEditSeq->fSuperior)
- itsEditSeq->fSuperior->RemoveSubView(itsEditSeq);
- delete itsEditSeq;
- #endif
- }
-
-
- void DAlnHIndex::Resize(DView* superview, Nlm_PoinT sizechange)
- {
- DPanel::Resize(superview, sizechange);
- }
-
- void DAlnView::Resize(DView* superview, Nlm_PoinT sizechange)
- {
- DTableView::Resize(superview, sizechange);
- }
-
- void DAlnView::GetReadyToShow()
- {
- // assume port is set??
- SelectFont();
- gAlnCharWidth = Nlm_CharWidth('G');
- gAlnCharHeight= Nlm_LineHeight() + 2; // Nlm_FontHeight()
- SetItemWidth(0, GetMaxCols(), gAlnCharWidth);
- SetItemHeight(0, GetMaxRows(), gAlnCharHeight);
- this->UpdateAllWidths();
- this->UpdateSize();
- }
-
- void DAlnIndex::GetReadyToShow()
- {
- //SelectFont(); //Nlm_SelectFont(fFont);
- SetItemWidth(0, GetMaxCols(), fViewrect.right-fViewrect.left-1); //<< width of view
- SetItemHeight(0, GetMaxRows(), gAlnCharHeight);
- }
-
- void DAlnITitle::GetReadyToShow()
- {
- // assume port is set??
- SelectFont();
- short charheight= Nlm_LineHeight(); // Nlm_FontHeight();
- SetItemWidth(0, GetMaxCols(), fViewrect.right-fViewrect.left-1); //<< width of view
- SetItemHeight(0, GetMaxRows(), charheight);
- }
-
- void DAlnView::Show()
- {
- GetReadyToShow();
- DTableView::Show();
- }
-
- void DAlnIndex::Show()
- {
- GetReadyToShow();
- DTableView::Show();
- }
-
- void DAlnView::Drag(Nlm_PoinT mouse)
- {
- DTableView::Drag(mouse); // sets fMouseStillDown= true
- }
-
- void DAlnIndex::Drag(Nlm_PoinT mouse)
- {
- DTableView::Drag(mouse); // sets fMouseStillDown= true
- }
-
- void DAlnHIndex::Drag(Nlm_PoinT mouse)
- {
- DPanel::Drag(mouse);
- }
-
- void DAlnView::Hold(Nlm_PoinT mouse)
- {
- DTableView::Hold(mouse);
- }
-
- void DAlnIndex::Hold(Nlm_PoinT mouse)
- {
- DTableView::Hold(mouse);
- }
-
- void DAlnHIndex::Hold(Nlm_PoinT mouse)
- {
- DPanel::Hold(mouse);
- }
-
- void DAlnView::Release(Nlm_PoinT mouse)
- {
- DTableView::Release(mouse);
- }
-
- void DAlnIndex::Release(Nlm_PoinT mouse)
- {
- DTableView::Release(mouse);
- }
-
- void DAlnHIndex::Release(Nlm_PoinT mouse)
- {
- DPanel::Release(mouse);
- }
-
-
- void DAlnView::DoubleClickAt(short row, short col)
- {
- #if 0
- //?? do this only on DAlnIndex dblclik??
- DSequence* ag= fSeqList->SeqAt(row);
- if (ag) fDoc->OpenSeqedWindow(ag);
- #endif
- }
-
-
- void DAlnIndex::Click(Nlm_PoinT mouse)
- {
- short row, col;
- //if (gLastCommand) { delete gLastCommand; gLastCommand= NULL; } //gLastCommand->Commit(); //??
-
- fDoc->fAlnView->DeInstallEditSeq();
- fDoc->fAlnView->SetEmptySelection(true);
-
- PointToCell( mouse, row, col);
- if (Nlm_dblClick)
- ;
- else if (IsSelected(row, col)) { //if (gKeys->shift())
- // slide/shift selected lines...
- DAlnShifter* shifter= new DAlnShifter();
- shifter->IAlnSlider( fDoc, this, fDoc->fAlnView, row);
- fCurrentTracker= shifter;
- }
- else {
- //if (fTabSelector) fTabSelector->suicide(); // is this delete causing bombs? YES, in motif
- fTabSelector= new DTabSelector( this);
- fCurrentTracker= fTabSelector;
- }
- DTableView::Click( mouse);
- }
-
-
- void DAlnITitle::Click(Nlm_PoinT mouse)
- {
- // damn, need this or the like for each user of DTableView::Click ...
- //if (gLastCommand) { delete gLastCommand; gLastCommand= NULL; } //gLastCommand->Commit(); //??
-
- //if (fTabSelector) fTabSelector->suicide(); // is this delete causing bombs? YES, in motif
- fTabSelector= new DTabSelector( this);
- fCurrentTracker= fTabSelector;
-
- DTableView::Click( mouse);
- }
-
-
-
-
-
- void DAlnView::Click(Nlm_PoinT mouse)
- {
- short row, col;
-
- //if (gLastCommand) { delete gLastCommand; gLastCommand= NULL; } //gLastCommand->Commit(); //??
-
- PointToCell( mouse, row, col);
- if (IsSelected(row, col)) {
- //if (fSlider) delete fSlider; // is this delete causing bombs?
- fSlider= new DAlnSlider();
- fSlider->IAlnSlider( fDoc, this, this, 0);
- fCurrentTracker= fSlider;
- }
- else {
- //if (fTabSelector) fTabSelector->suicide(); // is this delete causing bombs? YES, in motif
- #if MASKS
- if (fMaskLevel>0)
- fTabSelector= new DMaskSelector( this, fMaskLevel, fSeqList);
- else
- #endif
- fTabSelector= new DTabSelector( this);
- fCurrentTracker= fTabSelector;
- }
-
- DTableView::Click( mouse);
- }
-
-
- void DAlnView::TrackMouse( short aTrackPhase,
- Nlm_PoinT& anchorPoint, Nlm_PoinT& previousPoint,
- Nlm_PoinT& nextPoint, Nlm_Boolean mouseDidMove)
- {
- DTableView::TrackMouse( aTrackPhase, anchorPoint, previousPoint, nextPoint,mouseDidMove);
- }
-
-
- void DAlnView::TrackFeedback( short aTrackPhase,
- const Nlm_PoinT& anchorPoint, const Nlm_PoinT& previousPoint,
- const Nlm_PoinT& nextPoint, Nlm_Boolean mouseDidMove, Nlm_Boolean turnItOn)
- {
- DTableView::TrackFeedback( aTrackPhase, anchorPoint, previousPoint, nextPoint,
- mouseDidMove, turnItOn);
- }
-
-
- void DAlnIndex::DoubleClickAt(short row, short col)
- {
- DSequence* ag= fSeqList->SeqAt(row);
- if (ag) fDoc->OpenSeqedWindow(ag);
- }
-
- void DAlnITitle::DoubleClickAt(short row, short col)
- {
- }
-
-
-
- void DAlnView::SingleClickAt(short row, short col)
- {
- #if ETEXT
- if (!(fLocked || gKeys->shift() || gKeys->command() || gKeys->option() )) {
- SetEmptySelection( true);
- if (fDoc->fAlnIndex) fDoc->fAlnIndex->SetEmptySelection( true);
- InstallEditSeq(row,col,col,false);
- }
- else
- #endif
- #if MASKS
- if (fMaskLevel>0) {
- Nlm_RecT r;
- DSequence* ag= fSeqList->SeqAt(row);
- if (ag) {
- if (gKeys->shift()) ag->SetMaskAt(col,fMaskLevel);
- else ag->FlipMaskAt(col,fMaskLevel);
- }
- GetCellRect( row, col, r);
- InvalRect( r);
- }
- else
- #endif
- DTableView::SingleClickAt(row, col);
- //fDoc->SetViewMenu();
- }
-
- void DAlnIndex::SingleClickAt(short row, short col)
- {
- DTableView::SingleClickAt(row, col);
- //fDoc->SetViewMenu();
- }
-
- void DAlnITitle::SingleClickAt(short row, short col)
- {
- }
-
- void DAlnHIndex::Click(Nlm_PoinT mouse)
- {
- DPanel::Click(mouse);
- }
-
-
- void DAlnView::Scroll(Boolean vertical, DView* scrollee, short newval, short oldval)
- {
- short diff= newval - oldval;
- DTableView::Scroll(vertical, scrollee, newval, oldval);
-
- if (diff && fEditSeq && fEditSeq->fVisible) {
- Nlm_RecT r;
- short delta;
- if (vertical) {
- delta= diff * fItemHeight; // bad for variable line height
- fEditSeq->GetPosition( r);
- Nlm_OffsetRect( &r, 0, -delta);
- if (r.top < fRect.top || r.top >= fRect.bottom) DeInstallEditSeq();
- else fEditSeq->SetPosition( r);
- }
- else {
- // messy, undo bitmap scroll by TableView for just editseq rect...
- delta= diff * fItemWidth;
- fEditSeq->GetPosition(r);
- Nlm_ScrollRect(&r, delta, 0);
- // then redo scroll using edit method !
- fEditSeq->Scroll(vertical, scrollee, newval, oldval);
- }
- }
-
- if (scrollee == this) {
- if (vertical) {
- fDoc->fAlnIndex->Scroll(vertical, scrollee, newval, oldval);
- }
- else {
- fDoc->fAlnHIndex->Scroll(vertical, scrollee, newval, oldval);
- }
- }
- }
-
- void DAlnIndex::Scroll(Boolean vertical, DView* scrollee, short newval, short oldval)
- {
- DTableView::Scroll(vertical, scrollee, newval, oldval);
- if (scrollee == this) {
- if (vertical) {
- fDoc->fAlnView->Scroll(vertical, scrollee, newval, oldval);
- }
- else // horizontal
- fDoc->fAlnITitle->Scroll(vertical, scrollee, newval, oldval);
-
- }
- }
-
-
- void DAlnHIndex::Scroll(Boolean vertical, DView* scrollee, short newval, short oldval)
- {
- Nlm_RecT r;
- short delta;
- short diff= newval-oldval;
- ViewRect(r);
- if (vertical) {
- #if 0
- delta= diff * cHeight;
- Nlm_ScrollRect (&r, 0, -delta);
- if (diff<0) r.bottom= r.top - delta + Min(5,-delta/2);
- else r.top= r.bottom - delta - Min(5,delta/2);
- #endif
- }
- else {
- #if 1
- short cWidth= gAlnCharWidth;
- delta= diff * cWidth;
- Nlm_ScrollRect (&r, -delta, 0);
- // test fix for off-by-a-few-pixels in scroll...
- if (diff<0) r.right= r.left - delta + Min(5,-delta/2);
- else r.left= r.right - delta - Min(5,delta/2);
- #endif
- }
- this->Select(); // need for motif !
- this->InvalRect( r);
-
- if (scrollee == this) {
- if (!vertical) fDoc->fAlnView->Scroll(vertical, scrollee, newval, oldval);
- }
- }
-
-
-
- DSequence* DAlnView::SelectedSequence(short& selectedRow)
- {
- if (GetSelectedRow() != kNoSelection) {
- selectedRow= GetSelectedRow();
- return fSeqList->SeqAt(selectedRow);
- }
- else if (fDoc && fDoc->fAlnIndex->GetSelectedRow() != kNoSelection) {
- selectedRow= fDoc->fAlnIndex->GetSelectedRow();
- return fSeqList->SeqAt(selectedRow);
- }
- else {
- selectedRow= kNoSelection;
- return NULL;
- }
- }
-
-
- void DAlnView::UpdateSize()
- {
- long diff;
- if (fSeqList) diff= fSeqList->GetSize() - GetMaxRows();
- else diff= -GetMaxRows();
- ChangeRowSize( -1, diff); // -1 prevents redraw..else use fMaxRows
- if (fDoc && fDoc->fAlnIndex) fDoc->fAlnIndex->ChangeRowSize(-1, diff);
-
- #if MASKS
- if (diff>0) { //fMaskLevel>0 &&
- short i, nseq= fSeqList->GetSize();
- for (i=nseq-diff; i<nseq; i++) {
- DSequence* aseq= fSeqList->SeqAt(i);
- if (fMaskLevel>0 || aseq->Masks()) aseq->FixMasks();
- }
- }
- #endif
- }
-
-
- void DAlnView::UpdateWidth(DSequence* aSeq)
- {
- long alnlen= aSeq->LengthF() + 30;
- if (alnlen > GetMaxCols()) ChangeColSize( -1, alnlen-GetMaxCols());
- SetItemWidth( 0, GetMaxCols(), gAlnCharWidth);
- #if MASKS
- if (fMaskLevel>0 || aSeq->Masks()) aSeq->FixMasks();
- #endif
- //if (fDoc && fDoc->fAlnHIndex) fDoc->fAlnHIndex->UpdateWidth(); //keep ruler in sync
- }
-
- void DAlnView::UpdateAllWidths()
- {
- long alnlen= 0;
- short i, nseq= fSeqList->GetSize();
- for (i=0; i<nseq; i++) {
- DSequence* aSeq= fSeqList->SeqAt(i);
- alnlen= Max(alnlen, aSeq->LengthF());
- #if MASKS
- if (fMaskLevel>0 || aSeq->Masks()) aSeq->FixMasks();
- #endif
- }
- alnlen += 30;
- if (alnlen > GetMaxCols()) ChangeColSize( -1, alnlen-GetMaxCols());
- SetItemWidth( 0, GetMaxCols(), gAlnCharWidth);
- //if (fDoc && fDoc->fAlnHIndex) fDoc->fAlnHIndex->UpdateWidth(); //keep ruler in sync
- }
-
- void DAlnView::SetTextLock( Boolean turnon)
- {
- fLocked= turnon;
- if (fLocked) DeInstallEditSeq();
- }
-
-
- void DAlnView::SetViewMode(short viewmode)
- {
- switch (viewmode) {
- case kModeSlide:
- this->SetTextLock( true);
- if (this->fMaskLevel>0) this->Invalidate();
- this->fMaskLevel= 0;
- break;
-
- case kModeEdit:
- this->SetTextLock( false);
- if (this->fMaskLevel>0) this->Invalidate();
- this->fMaskLevel= 0;
- break;
-
- case kModeMask1:
- case kModeMask2:
- case kModeMask3:
- case kModeMask4: {
- this->SetTextLock( true);
- this->fMaskLevel= viewmode - kModeMask1 + 1;
- this->Invalidate();
- short i, nseq= fSeqList->GetSize();
- for (i=0; i<nseq; i++) fSeqList->SeqAt(i)->FixMasks();
- }
- break;
-
- default :
- break;
- }
- }
-
-
- // move this to DSeqCmds.h ...
- class DSetEditCmd : public DSeqChangeCmd {
- public:
- DSetEditCmd( DSeqDoc* itsAlnDoc, DView* itsView, DSequence* oldSeq, char* newbases):
- DSeqChangeCmd("edit seq", itsAlnDoc, itsView, NULL)
- {
- fOldSeqs= new DSeqList();
- fOldSeqs->InsertLast( oldSeq);
- DSequence* newSeq= MakeSequence( oldSeq->Name(), newbases, oldSeq->Info(), 0);
- fNewSeqs->InsertLast( newSeq);
- }
- };
-
-
- void DAlnView::DeInstallEditSeq()
- {
- if (fEditRow >= 0) {
- if (fEditSeq) {
- Nlm_RecT r;
- char* newbases = fEditSeq->GetText();
- if (StringCmp(newbases, fEditSeq->fSeq->Bases()) != 0) {
- #if 0
- // test if DSetEditCmd is cause of bombs when fEditSeq is used...
- // no -- this isn't it...
- fEditSeq->fSeq->SetBases(newbases);
- #else
- DSetEditCmd* cmd= new DSetEditCmd( fDoc, this, fEditSeq->fSeq, newbases);
- if (cmd) PostTask(cmd);
- #endif
- }
- MemFree( newbases);
-
- fEditSeq->GetPosition(r);
- fEditSeq->HideEdit();
- fDoc->SetEditText(NULL); //??
- InvalRect(r);
- }
- fEditRow= -1;
- }
-
- }
-
-
-
- void DAlnView::InstallEditSeq(short row, short selStart, short selEnd, Boolean doLight)
- {
-
- DeInstallEditSeq();
- //if (gLastEditView && gLastEditView != this) gLastEditView->DeInstallEditSeq();
-
- fEditRow= row;
- if (row >= 0) {
- Nlm_RecT r;
- DSequence* aSeq= fSeqList->SeqAt( row);
- this->GetRowRect( row, r);
- fEditSeq->fSeq= aSeq;
-
- r.left--; // fix off-by-one
- fEditSeq->SetPosition( r);
- fEditSeq->ShowEdit();
- fEditSeq->SetSelection( selStart, selEnd);
- if (fLeft>0) fEditSeq->Scroll(false, NULL, fLeft, 0);
- fDoc->SetEditText(fEditSeq); //??
-
- if (gLastCommand) { delete gLastCommand; gLastCommand= NULL; } //gLastCommand->Commit(); //??
- //gLastEditView= this;
- }
-
- }
-
-
- void DAlnView::registerInsertLast( DSequence* aSeq)
- {
- ChangeRowSize( GetMaxRows(), 1);
- if (fDoc && fDoc->fAlnIndex)
- fDoc->fAlnIndex->ChangeRowSize( GetMaxRows(), 1);
- UpdateWidth(aSeq);
- }
-
- void DAlnView::addToAlnList( DSequence* aSeq)
- {
- fSeqList->InsertLast( aSeq);
- //aSeq->fIndex= fSeqList->GetSize(); //??
- registerInsertLast( aSeq);
-
- #if NOT_NOW_MASKS
- // done via registerInsertLast -> UpdateWidth
- if (fMaskLevel>0 || aSeq->fMasks) aSeq->FixMasks();
- #endif
- }
-
-
- void DAlnView::MakeConsensus()
- {
- fSeqList->MakeConsensus();
- short arow= fSeqList->ConsensusRow();
- if (arow>0) {
- Nlm_RecT r;
- GetRowRect( arow, r);
- this->InvalRect( r);
- }
- }
-
-
- char* DAlnView::FindCommonBases( short minCommonPerCent)
- {
- // THIS_IS_OBSOLETE
- char *hCommon, *hFirst = NULL;
- //gMinCommonPercent= minCommonPerCent;
- hCommon= fSeqList->FindCommonBases(DSeqList::gMinCommonPercent, hFirst);
- if (hFirst) MemFree( hFirst);
- return hCommon;
- }
-
-
- void DAlnView::HiliteORFs()
- {
- long start, stop;
- long nseq= fSeqList->GetSize();
- if (fMaskLevel>0)
- for (long iseq= 0; iseq<nseq; iseq++) {
- DSequence* aSeq= fSeqList->SeqAt(iseq);
- long alen= aSeq->LengthF();
- aSeq->ClearMask(fMaskLevel);
- aSeq->ClearSelection();
-
- aSeq->SearchORF( start, stop);
- while (start>=0) {
- if (stop<start) stop= alen;
- for (long ibase=start; ibase<=stop; ibase++)
- aSeq->SetMaskAt( ibase, fMaskLevel);
- if (stop >= alen) start= -1;
- else {
- aSeq->SetSelection( stop+1, alen);
- aSeq->SearchORF( start, stop);
- }
- }
- }
- this->Invalidate();
- }
-
-
- void DAlnView::HiliteCommonBases()
- {
- #if 1
- char * hFirst = NULL;
- char * hCommon= fSeqList->FindCommonBases(DSeqList::gMinCommonPercent, hFirst);
-
- long nseq= fSeqList->GetSize();
- if (fMaskLevel>0)
- for (long iseq= 0; iseq<nseq; iseq++) {
- DSequence* aSeq= fSeqList->SeqAt(iseq);
- long alen= aSeq->LengthF();
- char * hf = hFirst;
- char * hc = hCommon;
- char * bc = aSeq->Bases();
- aSeq->ClearMask(fMaskLevel);
- for (long ibase=0; ibase<alen; ibase++, hf++, hc++, bc++)
- if (iseq >= (unsigned char) *hf && toupper(*bc) == *hc)
- aSeq->SetMaskAt( ibase, fMaskLevel);
- }
- this->Invalidate();
- MemFree(hCommon);
- MemFree(hFirst);
- #endif
-
- #if THIS_IS_OBSOLETE
- char *hCon, *hSeq, *hFirst, *hMaxbase;
- long maxlen;
- short arow;
-
- DSequence* cons= fSeqList->Consensus();
- if (!cons) cons= (DSequence*) fSeqList->First();
-
- if (cons) {
- arow= fSeqList->GetIdentityItemNo( cons);
- hCon= cons->Bases();
- hMaxbase= fSeqList->FindCommonBases(DSeqList::gMinCommonPercent, hFirst);
-
- maxlen= StrLen(hMaxbase);
- this->SetEmptySelection( true);
- long iseq, nseq= fSeqList->GetSize();
- for (iseq= 0; iseq<nseq; iseq++) {
- DSequence* aSeq= fSeqList->SeqAt(iseq);
- if (!aSeq->IsConsensus() && aSeq->Kind() != DSequence::kOtherSeq) {
- hSeq= aSeq->Bases();
- for (short ibase=0; ibase<maxlen; ibase++) {
- if ( toupper(hSeq[ibase]) == hMaxbase[ibase] )
- this->SelectCells( iseq, ibase, false, false);
- }
- }
- }
- this->InvalidateSelection();
- MemFree(hMaxbase);
- MemFree(hFirst);
- }
- #endif
- }
-
-
-
-
-
-
- void DAlnView::DrawAlnInStyle( baseColors colors, Boolean swapBackColor,
- char* pText, long indx, long len, short row)
- {
- #if MASKS
-
- // ?? do we want this? main use of styles is in PrettyPrint...
-
- Nlm_PoinT pt;
- long endx, i, pend, skip;
- char ch, lastch;
- Nlm_RecT crec; // set this to rect about draw char...
- short maskval;
-
- Boolean dostyles= (fCurSeq && fCurSeq->MasksOk());
- if (!dostyles) {
- DrawAlnColors( colors, swapBackColor, pText, indx, len,row);
- return;
- }
-
- long cw= GetItemWidth(); //gAlnCharWidth; //Nlm_CharWidth('G');
- long cht= GetItemHeight();
- Nlm_GetPen( &pt);
- if (pt.x < 0) {
- skip= (-pt.x) / cw;
- indx += skip;
- len -= skip;
- pt.x += skip*cw;
- Nlm_MoveTo( pt.x, pt.y);
- }
- pend= len * cw;
-
- if (pend > GetRect().right) {
- skip= (pend - GetRect().right) / cw;
- len -= skip;
- }
- endx= indx + len - 1;
- lastch= 0;
-
- for (i= indx; i<=endx; i++) {
- ch= pText[i];
- if (ch >= ' ') {
- if (ch!=lastch) Nlm_SetColor( colors[ch-' ']);
- Nlm_PaintChar(ch);
- lastch= ch;
- if (fMaskLevel>0) {
- maskval= fCurSeq->MaskAt(i, fMaskLevel);
- if (maskval>0) {
- Nlm_LoadRect( &crec, pt.x, pt.y-cht+2, pt.x+cw, pt.y+2); //??
- //Nlm_FrameRect( &crec); //?? doesn't show on XMotif?
- DTableView::InvertRect( crec);
- }
- }
- pt.x += cw;
- // !? must reset some of drawing environ !? > Font !
- }
- }
- Nlm_Black();
-
- #else
- DrawAlnColors( colors, swapBackColor, pText, indx, len, row);
- #endif
- }
-
-
- void DAlnView::DrawAlnColors(baseColors colors, Boolean swapBackColor,
- char* pText, long indx, long len, short row)
- {
- Nlm_PoinT pt;
- long endx, i, pend, skip;
- char ch, lastch;
-
- long cw= GetItemWidth(); //gAlnCharWidth; //Nlm_CharWidth('G');
- Nlm_GetPen( &pt);
- if (pt.x < 0) {
- skip= (-pt.x) / cw;
- indx += skip;
- len -= skip;
- Nlm_MoveTo( pt.x + skip*cw, pt.y);
- }
- pend= len * cw;
-
- if (pend > GetRect().right) {
- skip= (pend - GetRect().right) / cw;
- len -= skip;
- }
- endx= indx + len - 1;
-
- //-- backcolor not showing -- need erase or something...
- //if (swapBackcolor) RGBForeColor( colors[' '-' ']); else RGBBackColor( colors[' '-' ']);
-
- //Nlm_CopyMode(); //?? assume?
- lastch= 0;
- for (i= indx; i<=endx; i++) {
- ch= pText[i];
- if (ch >= ' ') {
- // if (swapBackcolor) RGBBackColor( colors[ch-' ']); else
- if (ch!=lastch) Nlm_SetColor( colors[ch-' ']);
- Nlm_PaintChar(ch);
- lastch= ch;
- }
- }
- Nlm_Black();
- }
-
-
-
-
- void DAlnView::DrawAllColors(Nlm_RecT r, short row)
- {
- #if MASKS
- #define DRAWALN DrawAlnInStyle
- #else
- #define DRAWALN DrawAlnColors
- #endif
-
- long stopcol, startcol = GetLeft();
- long newright= r.left;
-
- for (stopcol= startcol; stopcol<GetMaxCols() && newright<r.right; stopcol++) {
- //if (fWidths) newright += fWidths[startcol]; else
- newright += GetItemWidth();
- // optimize later -- check update region by each char rect ...
- //if (Nlm_RectInRgn (&item_rect, Nlm_updateRgn)) done= true;
- }
-
- DSequence* aSeq= fSeqList->SeqAt(row);
- if (aSeq && aSeq->Bases()) {
- char* hSeq= aSeq->Bases();
- fCurSeq= aSeq;
- long len= Min( aSeq->LengthF(), stopcol) - startcol;
- if (len>0 && hSeq) {
- Nlm_MoveTo( r.left, r.bottom-2); //bottom-5
- if (aSeq->Kind() == DSequence::kAmino)
- DRAWALN(DBaseColors::gAAcolors, gSwapBackground, hSeq, startcol, len, row);
- else
- DRAWALN(DBaseColors::gNAcolors, gSwapBackground, hSeq, startcol, len, row);
- }
- }
- fColsDrawn= stopcol - startcol;
- }
-
- void DAlnView::DrawNoColors(Nlm_RecT r, short row)
- {
- long stopcol, startcol = GetLeft();
- long newright= r.left;
- short cwidth= GetItemWidth(); // Nlm_CharWidth('G'); //fItemWidth
-
- for (stopcol= startcol; stopcol<GetMaxCols() && newright<r.right; stopcol++) {
- //if (fWidths) newright += fWidths[startcol]; else
- newright += cwidth;
- // optimize later -- check update region by each char rect ...
- //if (Nlm_RectInRgn (&item_rect, Nlm_updateRgn)) done= true;
- }
-
- DSequence* aSeq= fSeqList->SeqAt(row);
- if (aSeq && aSeq->Bases()) {
- char *s, se, *hSeq= aSeq->Bases();
- long len= Min( aSeq->LengthF(), stopcol) - startcol;
- if (len>0 && hSeq) {
- #if MASKS
- if (fMaskLevel>0) {
- short atx= r.left;
- short aty= r.bottom-2;
- stopcol= startcol + len;
- for (long i= startcol; i<stopcol; i++) {
- Nlm_MoveTo(atx, aty);
- Nlm_PaintChar(hSeq[i]);
- short maskval= aSeq->MaskAt(i, fMaskLevel);
- if (maskval>0) {
- Nlm_RecT crec;
- Nlm_LoadRect( &crec, atx, r.top, atx+cwidth, r.bottom);
- //Nlm_FrameRect( &crec); //<< ? bad for Motif, also messy looking
- DTableView::InvertRect( crec);
- }
- atx += cwidth;
- }
- }
- else
- #endif
- {
- Nlm_MoveTo( r.left, r.bottom-2); //bottom-5
- s= hSeq+startcol;
- se= s[len];
- s[len]= 0;
- Nlm_PaintString( s);
- s[len]= se;
- //Nlm_DrawText( &r, hSeq+startcol, len, 'l', false); // gray== false
- }
- }
- }
- fColsDrawn= stopcol - startcol;
- }
-
-
- void DAlnView::Draw()
- {
- DTableView::Draw();
- }
-
-
- void DAlnView::DrawRow(Nlm_RecT r, short row)
- {
- // DTableView::Draw() does SelectFont(fFont)
- if (fEditRow == row) {
- // do nothing? , fEditSeq handle's redraw ??
- fColsDrawn= 0;
- }
- else if (fDoc && fDoc->fUseColor)
- DrawAllColors(r, row);
- else
- DrawNoColors(r, row);
- }
-
-
- void DAlnIndex::DrawCell(Nlm_RecT r, short row, short col)
- {
- #if 0
- long stopcol, startcol = fLeft;
- long newright= r.left;
- short cwidth= Nlm_CharWidth('G'); //fItemWidth
-
- for (stopcol= startcol; stopcol<fMaxCols && newright<r.right; stopcol++) {
- //if (fWidths) newright += fWidths[startcol]; else
- newright += cwidth;
- // optimize later -- check update region by each char rect ...
- //if (Nlm_RectInRgn (&item_rect, Nlm_updateRgn)) done= true;
- }
- #endif
-
- // add cols for Kind(), Length(), Origin(), UpdateTime(), Info()(wide col..better in box)
-
- DSequence* aSeq= fSeqList->SeqAt(row);
- if (aSeq) switch (col) {
- case 0:
- {
- char* hSeq= aSeq->Name();
- Nlm_DrawString( &r, hSeq, 'l', false);
- return;
- }
- case 1:
- {
- char buf[128];
- sprintf(buf,"%d ", aSeq->LengthF()); // switch to ostrstream !?
- Nlm_DrawString( &r, buf, 'r', false);
- return;
- }
- case 2:
- {
- char* hSeq= aSeq->KindStr();
- Nlm_DrawString( &r, hSeq, 'l', false);
- return;
- }
- case 3:
- {
- char buf[128];
- sprintf(buf,"%8lx ", aSeq->Checksum()); // switch to ostrstream !?
- Nlm_DrawString( &r, buf, 'l', false);
- return;
- }
- }
- }
-
-
- void DAlnITitle::DrawCell(Nlm_RecT r, short row, short col)
- {
- switch (col) {
- case 0:
- {
- Nlm_DrawString( &r, "Name", 'l', false);
- return;
- }
- case 1:
- {
- Nlm_DrawString( &r, "Bases", 'l', false);
- return;
- }
- case 2:
- {
- Nlm_DrawString( &r, "Kind", 'l', false);
- return;
- }
- case 3:
- {
- Nlm_DrawString( &r, "Checksum", 'l', false);
- return;
- }
- }
- }
-
- void DAlnHIndex::Draw()
- {
- Nlm_RecT r;
- short atx, aty;
- char nums[128];
-
- fDoc->fAlnView->SelectFont();
- ViewRect( r);
- long stopcol, startcol = fDoc->fAlnView->GetLeft();
- long newright= r.left;
- short cwidth= Nlm_CharWidth('G');
-
- #if 0
- Nlm_RecT vr;
- // is ViewRect bad !? (too short) YES - isn't grown !?
- fDoc->fAlnView->ViewRect( vr);
- r.right= vr.right; //??
- Nlm_ClipRect( &r); // ?? why is hindex clipped to small !?
- #endif
-
- for (stopcol= startcol;
- stopcol < fDoc->fAlnView->GetMaxCols() && newright<r.right;
- stopcol++) {
- newright += cwidth;
- }
-
- long len= stopcol - startcol;
- atx= r.left;
- aty= r.bottom;
- for (short i= startcol; i<=stopcol; i++) {
- if (i == 0) ; //skip
- else if (i % 10 == 0) {
- Nlm_MoveTo(atx, aty);
- Nlm_LineTo(atx, aty-2);
- sprintf( nums, "%d", i);
- short ws= Nlm_StringWidth(nums);
- Nlm_MoveTo( atx-(ws/ 2), aty-3);
- Nlm_PaintString(nums);
- //Nlm_DrawString( &r1, nums, 'c', false);
- }
- else if (i % 5 == 0) {
- Nlm_MoveTo( atx, aty);
- Nlm_LineTo(atx, aty-6);
- }
- atx += cwidth;
- }
- }
-
-
-
-
-
-
- #if FIX_LATER
- Boolean DAlnView::ContainsClipType(long aType) // override
- {
- return (aType == kAlnScrapType);
- //!? also (aType == 'TEXT') can be pasted as seq... w/ SeqReadScrap...
- }
- #endif
-
- #if FIX_LATER
- void DAlnView::WriteToDeskScrap() // override
- {
- short format = kGenBank;
- //if (fDoc->fFormatPop) format= fDoc->fFormatPop->GetValue();
- fSeqList->ClearSelections();
- char* textScrap= fSeqList->doWriteHandle( format);
- short err = gClipboardMgr->PutDeskScrapData('TEXT', textScrap);
- MemFree( textScrap);
- }
- #endif
-
-
-
-
-
-
-
- // DAlnIndex ------------------
-
-
- char* DAlnIndex::GetItemTitle(short item, char* title, size_t maxsize)
- {
- if (fSeqList && item <= fSeqList->GetSize()) {
- DSequence* aSeq= fSeqList->SeqAt(item);
- if (aSeq) {
- if (!title) title= (char*) MemNew( maxsize);
- StrNCpy( title, aSeq->Name(), maxsize);
- return title;
- }
- }
- return NULL;
- }
-
-
- #if FIX_LATER
-
- void TAlnIndex::UpdateSize(void)
- VAR diff: integer;
- {
- if ((fAlnView!=NULL)) {
- diff= fAlnView->fNumOfRows - fNumOfRows;
- if ((diff>0)) InsRowLast( 1, fAlnView->fRowheight)
- else if ((diff<0)) DelItemLast( -diff);
- } else
- DelItemLast(fNumOfRows);
- }
-
- void TAlnIndex::ReSelect(RgnHandle indexRegion)
- VAR aCell: GridCell;
- {
- /*-----
- aCell = (*indexRegion)->rgnBBox.topLeft;
- if (!IsCellVisible(aCell)) PositionAtCell(aCell);
- ----*/
-
- if (!EqualRect((*indexRegion)->rgnBBox, (*fSelections)->rgnBBox)) {
- /*---- ??
- WITH fDoc){
- fAlnView->SetEmptySelection(kHighlight);
- }
- -----*/
- SetSelection(indexRegion, kDontExtend, kHighlight, kSelect);
- }
- }
-
-
-
- TAlnIndex::HandleMouseDown( VPoint theMouse, TToolboxEvent event,
- hysteresis: Point):Boolean; // override
- {
- fAlnView->DeInstallEditSeq();
- fAlnView->SetEmptySelection(kHighlight);
-
- HandleMouseDown= inherited::HandleMouseDown(theMouse,event,hysteresis);
- }
-
- void TAlnIndex::DoMouseCommand(VPoint VAR theMouse, TToolboxEvent event,
- Point hysteresis) // override
- VAR
- aRow, aCol : short;
- aCell : GridCell;
- aAlnShifter : TAlnShifter;
- boolean aDoubleClick;
- aName : Str255;
- vpt : VPoint;
- GridViewPart gridPart;
- aSeq : DSequence;
-
- {
- aDoubleClick= event->fClickCount > 1;
- gridPart= IdentifyPoint(theMouse, aCell);
- aRow= aCell.y;
-
- if (aDoubleClick) {
- aSeq= DSequence(fSeqList->At(aRow));
- if (aSeq!=NULL)) TAlnDoc(fDocument)->OpenSeqedWindow(aSeq);
- }
- else if ((event.IsShiftKeyPressed |event->IsCommandKeyPressed())) {
- inherited::DoMouseCommand(theMouse,event,hysteresis)
- }
- else if (gridPart != badChoice) {
- aCell = VPointToLastCell(theMouse);
- //if TRUE then begin
- if (isCellSelected(aCell)) {
- GetItemText(aRow, aName);
- New(aAlnShifter);
- FailNIL(aAlnShifter);
- aAlnShifter->IAlnShifter(this, fAlnView, aRow, aName);
- PostCommand( aAlnShifter);
- } else
- inherited::DoMouseCommand(theMouse,event,hysteresis);
- }
- }
-
- #endif // FIX_LATER
-
-
-
-
-
-
-
-
-
-
- class DSeqFormatPopup : public DPopupList
- {
- public:
- DSeqFormatPopup(long id, DView* superior, short defaultFormat);
- virtual short GetValue() { return DSeqFile::kMinFormat + DPopupList::GetValue() - 1; }
- };
-
- DSeqFormatPopup::DSeqFormatPopup(long id, DView* superior, short defaultFormat) :
- DPopupList(id,superior,true)
- {
- for (short i= DSeqFile::kMinFormat; i<=DSeqFile::kMaxFormat; i++)
- this->AddItem( (char*)DSeqFile::FormatName(i));
- this->SetValue(defaultFormat);
- }
-
-
-
- class DAlnModePopup : public DPopupList
- {
- public:
- DAlnModePopup(long id, DView* superior, short defaultvalue);
- virtual short GetValue() { return DAlnView::kModeSlide + DPopupList::GetValue() - 1; }
- };
-
- DAlnModePopup::DAlnModePopup(long id, DView* superior, short defaultvalue) :
- DPopupList(id,superior,true)
- {
- AddItem( "Slide bases");
- AddItem( "Edit bases");
- AddItem( "Select mask 1");
- AddItem( "Select mask 2");
- AddItem( "Select mask 3");
- AddItem( "Select mask 4");
- this->SetValue(defaultvalue+1);
- }
-
-
-
- // class DAlnFindDialog
-
- class DAlnFindDialog : public DFindDialog {
- public:
- DSequence* fSequence;
- DAlnView* fAlnView;
- short fRow;
- char * fLastTarget;
- long fLastMatch;
- DAlnFindDialog( DSequence* itsSeq, DAlnView* itsView);
- virtual void DoFind();
- virtual void BuildDlog();
- };
-
- DAlnFindDialog::DAlnFindDialog( DSequence* itsSeq, DAlnView* itsView) :
- fSequence(itsSeq), fAlnView( itsView),
- fLastTarget(NULL), fRow(-1), fLastMatch(-1)
- {
- }
-
- void DAlnFindDialog::BuildDlog()
- {
- DFindDialog::BuildDlog();
-
- DView* av;
- av= FindSubview(replaceId); if (av) { av->Disable(); } //av->Hide();
- av= FindSubview(replaceFindId); if (av) { av->Disable(); }
- av= FindSubview(replaceAllId); if (av) { av->Disable(); }
- av= FindSubview(cBackwards); if (av) { av->Disable(); }
- av= FindSubview(cFullWord); if (av) { av->Disable(); }
- av= FindSubview(cCaseSense); if (av) { av->Disable(); }
- if (fReplaceText) fReplaceText->Disable();
- }
-
- void DAlnFindDialog::DoFind()
- {
- long firstBase, nBases, match;
- const char *target;
- Boolean back;
- Nlm_RecT selr;
- short selrow;
-
- fSequence= fAlnView->SelectedSequence(selrow);
- fRow= selrow;
- if (fSequence) {
- fSequence->UpdateFlds();
- selr= fAlnView->GetSelRect();
- selr.top= fRow;
- selr.bottom= fRow+1; //??
- firstBase= selr.left;
- nBases= 0; //selr.right - firstBase;
- fSequence->SetSelection( firstBase, nBases);
- target= this->GetFind();
- back = this->Backwards();
- if (target && *target) {
- if (fLastTarget && (StringCmp(target, fLastTarget)==0) && firstBase == fLastMatch)
- match= fSequence->SearchAgain();
- else {
- if (fLastTarget) MemFree(fLastTarget);
- fLastTarget= StrDup(target);
- match= fSequence->Search( (char*)target, back);
- }
- fLastMatch= match;
- if (match>=0) {
- nBases= StrLen(target);
- fSequence->SetSelection( match, nBases);
- selr.left= match;
- selr.right= match + nBases;
- fAlnView->SelectCells( selr); // !? this is bad
- //fAlnView->InvalidateSelection();
- }
- }
- }
- }
-
-
-
- //class DSeqDoc
-
-
- DSeqDoc::DSeqDoc( long id, DSeqList* itsSeqList, char* name) :
- DWindow( id, gApplication),
- fAlnView(NULL), fAlnIndex(NULL), fAlnITitle(NULL),
- fSeqList(itsSeqList), fPrintDoc(NULL),
- fHeadline(NULL), fFormatPop(NULL),
- fUpdateTime(0), fDocTitle(NULL),
- fInFormat(DSeqFile::kGenBank), // kNoFormat
- fSaveSelection(false),
- //fLockButton(NULL), fColorButton(NULL), fMonoButton(NULL),
- fColorCheck(NULL), fLockCheck(NULL),
- fUseColor(false)
- {
- short width= -1, height= -1, left= -10, top= -20; // default window loc
- if (gTextFont == NULL) gTextFont= Nlm_programFont;
- if (gSeqFont == NULL) gSeqFont= Nlm_programFont;
-
- if (!Nlm_EmptyRect(&fgWinRect)) {
- // these two are causing resize to fail >> width & height setting !!
- //width= MAX( 40, fgWinRect.right - fgWinRect.left);
- //height= MAX( 50, fgWinRect.bottom - fgWinRect.top);
- left= MAX(20,fgWinRect.left);
- top = MAX(40,fgWinRect.top);
- }
-
- this->InitWindow( document, width, height, left, top, name);
- gDefSeqName= name;
-
- if (!fSeqList) fSeqList= new DSeqList();
- //fSeqList->AddNewSeq(); // install 1 blank seq for new doc
- }
-
-
- DSeqDoc::~DSeqDoc()
- {
- #if 0
- // done now as part of ~DTaskMaster !
- if (gLastCommand) {
-
- // !! MUST delete any tasks/commands owned by window in task queue !!
- // at least any 'edit seq' tasks...
-
- if (((DView*)gLastCommand->fSource)->GetWindow() == this) {
- delete gLastCommand; gLastCommand= NULL;
- }
- }
- #endif
- if (fSeqList) { fSeqList->FreeAllObjects(); fSeqList->suicide(); }
- }
-
- void DSeqDoc::FreeData()
- {
- if (fSeqList) { fSeqList->FreeAllObjects(); }
- }
-
-
- Boolean DSeqDoc::IsSeqFile(DFile* aFile)
- {
- // this is a static function, usable w/o a DGopherListDoc object
- if (fgTestSeqFile && aFile && aFile->Exists()) {
- aFile->OpenFile();
- short format= DSeqFile::SeqFileFormatWrapper( aFile);
- return (format != DSeqFile::kUnknown);
- }
- else
- return false;
- }
-
- void DSeqDoc::MakeGlobalsCurrent()
- {
- ViewRect( fViewrect); // get current rect...
- if (!Nlm_EmptyRect(&fViewrect)) fgWinRect= fViewrect;
- if (fLockCheck) fgLockText= fLockCheck->GetStatus();
- if (fColorCheck) fgUseColor= fColorCheck->GetStatus();
- if (fModePop) fgViewMode= fModePop->GetValue();
- }
-
- void DSeqDoc::Close()
- {
- #if 1
- DList* winlist= gWindowManager->GetWindowList();
- short i, nwin= winlist->GetSize();
- for (i=0; i<nwin; i++) {
- DWindow* awin= (DWindow*) winlist->At(i);
- if (awin->Id() == DSeqedWindow::kId
- && ((DSeqedWindow*) awin)->fMainDoc == this) {
- delete awin; // ?? or awin->Close();
- }
- }
- #endif
-
- MakeGlobalsCurrent();
- DWindow::Close();
- }
-
- void DSeqDoc::ResizeWin()
- {
- DWindow::ResizeWin();
- MakeGlobalsCurrent();
- }
-
- void DSeqDoc::Open(DFile* aFile)
- {
- Boolean isempty= (fSeqList->GetSize() < 1);
- if ( ReadFrom( aFile, true) ) {
- if (isempty) this->SetTitle((char*)aFile->GetShortname());
- this->Open();
- }
- else
- if (isempty) this->suicide();
- }
-
-
- // static
- void DSeqDoc::NewSeqDoc()
- {
- DSeqDoc* newdoc= new DSeqDoc( DSeqDoc::kSeqdoc, NULL, (char*)DFileManager::kUntitled);
- newdoc->Open();
- newdoc->EditSeqs(); //?? make it real obvious to beginners?
- }
-
- // static
- void DSeqDoc::GetGlobals()
- {
- char* onoffs;
-
- SeqDocPrefs(kSeqDocPrefInit);
- DSeqPrintDoc::GetGlobals();
- SeqPrintPrefs(kSeqPrintPrefInit);
-
- onoffs= (fgLockText) ? "1" : "0";
- fgLockText= gApplication->GetPrefVal( "fgLockText", "windows", onoffs);
- onoffs= (fgUseColor) ? "1" : "0";
- fgUseColor= gApplication->GetPrefVal( "fgUseColor", "windows", onoffs);
- fgViewMode= gApplication->GetPrefVal( "fgViewMode", "seqdoc", "0");
-
- {
- //350, 200
- char* srect = gApplication->GetPref( "fgWinRect", "windows", "30 40 450 220");
- #if 1
- // sscanf is failing on Mac/codewar !! used to work
- if (srect) {
- char* cp= srect;
- while (*cp && isspace(*cp)) cp++;
- fgWinRect.left= atoi( cp);
-
- while (*cp && !isspace(*cp)) cp++;
- while (*cp && isspace(*cp)) cp++;
- fgWinRect.top= atoi( cp);
-
- while (*cp && !isspace(*cp)) cp++;
- while (*cp && isspace(*cp)) cp++;
- fgWinRect.right= atoi( cp);
-
- while (*cp && !isspace(*cp)) cp++;
- while (*cp && isspace(*cp)) cp++;
- fgWinRect.bottom= atoi( cp);
- }
- #else
- if (srect) sscanf( srect, "%d%d%d%d", &fgWinRect.left, &fgWinRect.top,
- &fgWinRect.right, &fgWinRect.bottom);
- #endif
- MemFree(srect);
- }
- }
-
- // static
- void DSeqDoc::SaveGlobals()
- {
- gApplication->SetPref( (int) fgLockText,"fgLockText","windows");
- gApplication->SetPref( (int) fgUseColor, "fgUseColor","windows");
- gApplication->SetPref( (int) fgViewMode, "fgViewMode","seqdoc");
-
- if (!Nlm_EmptyRect(&fgWinRect)) {
- char srect[128];
- sprintf( srect, "%d %d %d %d", fgWinRect.left, fgWinRect.top,
- fgWinRect.right, fgWinRect.bottom);
- gApplication->SetPref( srect, "fgWinRect", "windows");
- }
- }
-
-
- void DSeqDoc::Open()
- {
- DView* super;
- short width, height;
- Nlm_PoinT nps;
- DPrompt* pr;
- Boolean selectone= false;
-
- if (!fSeqList) fSeqList= new DSeqList();
- if (fSeqList->GetSize() == 0) {
- fSeqList->AddNewSeq(); // install 1 blank seq for new doc
- selectone= true;
- }
- if (!fAlnView || !fAlnIndex || !fAlnHIndex || !fAlnITitle) {
- super= this;
- fColorCheck= new DCheckBox(kColorButHit,super,"Color bases");
- fColorCheck->SetStatus(fgUseColor);
- fUseColor= fgUseColor;
- super->NextSubviewToRight();
- #if MASKS
- pr= new DPrompt(0,super," Mode:",0, 0, Nlm_programFont);
- super->NextSubviewToRight();
- fModePop= new DAlnModePopup(kModePopup,super,fgViewMode);
- fLockCheck= NULL;
- #else
- fLockCheck= new DCheckBox(kLockButHit,super,"Lock text");
- fLockCheck->SetStatus(fgLockText);
- #endif
- super->NextSubviewToRight();
- pr= new DPrompt(0,super," File format:",0, 0, Nlm_programFont);
- super->NextSubviewToRight();
- fFormatPop= new DSeqFormatPopup(0,super,fInFormat);
- super->NextSubviewBelowLeft();
-
- // left group : titleline over name table
- DCluster* grouper= new DCluster( 0, this, 0, 0, true); // was 0,0 for w,h
- grouper->SetResize( DView::fixed, DView::relsuper);
- super= grouper;
-
- fAlnITitle= new DAlnITitle(0, super, 80, Nlm_stdLineHeight);
- super->NextSubviewBelowLeft();
-
- //width= 350; height= 200;
- super->GetNextPosition( &nps);
- width = MAX( 40, fgWinRect.right - fgWinRect.left) - Nlm_vScrollBarWidth - nps.x;
- height= MAX( 60, fgWinRect.bottom - fgWinRect.top) - Nlm_hScrollBarHeight - nps.y;
- fAlnIndex= new DAlnIndex(0, super, this, fSeqList, 80, height); // pixwidth,height
- // ^^ needs to be user changable ??
- super= this;
- super->NextSubviewToRight();
-
- // right group : index topline over bases table
- grouper= new DCluster( 0, this, 0, 0, true); // was 0,0 wid,hgt
- grouper->SetResize( DView::relsuper, DView::relsuper);
- super= grouper;
- super->GetNextPosition( &nps);
- width = MAX( 40, fgWinRect.right - fgWinRect.left) - Nlm_vScrollBarWidth - nps.x;
- height= MAX( 60, fgWinRect.bottom - fgWinRect.top) - Nlm_hScrollBarHeight - nps.y;
- fAlnHIndex= new DAlnHIndex(0, super, this, fSeqList, width, Nlm_stdLineHeight);
- super->NextSubviewBelowLeft();
-
- //width= 350; height= 200;
- super->GetNextPosition( &nps);
- width = MAX( 40, fgWinRect.right - fgWinRect.left) - Nlm_vScrollBarWidth - nps.x;
- height= MAX( 60, fgWinRect.bottom - fgWinRect.top) - Nlm_hScrollBarHeight - nps.y;
- fAlnView= new DAlnView(0, super, this, fSeqList, width, height); // pixwidth,height
- fAlnView->SetTextLock( fgLockText);
- super= this;
-
- #if ETEXT
- //if (gLastEditView) gLastEditView->DeInstallEditSeq();
- {
- Nlm_PoinT nps, saveps;
- GetNextPosition( &saveps);
- nps.x= 1; nps.y= 1; // locate dialog item
- SetNextPosition( nps);
- //gDialogTextMultiline= false;
- DAlnSequence* eseq= new DAlnSequence( 0, this);
- fAlnView->fEditSeq= eseq;
- //this->SetEditText(eseq);
- eseq->fVisible= true;
- eseq->HideEdit(); // eseq->Disable(); eseq->Hide();
- this->SetEditText(NULL);
- SetNextPosition( saveps);
- }
- #endif
-
- }
- fSaveHandler= this;
- fPrintHandler= this;
-
- if (!fFindDlog) fFindDlog= new DAlnFindDialog( NULL, fAlnView);
-
- this->Select(); // for motif
- this->CalcWindowSize();
- fAlnView->GetReadyToShow(); // do before others ...
- if (fAlnIndex) fAlnIndex->GetReadyToShow();
- fAlnITitle->GetReadyToShow();
- //fAlnHIndex->GetReadyToShow();
- fAlnView->SetViewMode(fgViewMode);
- if (selectone && fAlnIndex) fAlnIndex->SelectCells(0,0);
-
- DWindow::Open();
- }
-
-
- void DSeqDoc::Activate()
- {
- if (fAlnView && fAlnView->fEditSeq && fAlnView->fEditSeq->fVisible)
- fAlnView->fEditSeq->selectAction();
- gCursor->arrow();
- DWindow::Activate();
- }
-
- void DSeqDoc::Deactivate()
- {
- if (fAlnView && fAlnView->fEditSeq) fAlnView->fEditSeq->deselectAction();
- DWindow::Deactivate();
- }
-
- void DSeqDoc::Print()
- {
- // fix this to print more of window !
- //fAlnView->Print();
-
- // or do prettyprint...
- MakeSeqPrint( false);
- fPrintDoc->PrintDoc();
- }
-
- Boolean DSeqDoc::IsMyTask(DTask* theTask)
- {
- #if 0
- if (theTask->fKind == kSeqDoc) {
- ProcessTask( theTask);
- return true;
- }
- else
- #endif
- return DWindow::IsMyTask(theTask);
- }
-
- void DSeqDoc::ProcessTask(DTask* theTask)
- {
- if (theTask->fNumber == -987654) {
-
- }
- else {
- DWindow::ProcessTask(theTask);
- }
- }
-
-
- void DSeqDoc::SortView(DSeqList::Sorts sortorder)
- {
- fSeqList->SortList(sortorder);
- fAlnView->Invalidate();
- if (fAlnIndex) fAlnIndex->Invalidate();
- }
-
-
- void DSeqDoc::AddSeqToList(DSequence* item)
- {
- fAlnView->addToAlnList( item);
- //fAlnView->SelectCells( fAlnView->GetMaxRows()-1, fAlnView->GetMaxCols());
- if (fAlnIndex) fAlnIndex->SelectCells( fAlnView->GetMaxRows()-1, 0);
- #if 0
- this->Changed( 1, this);
- #endif
- }
-
-
-
- void DSeqDoc::AddNewSeqToList()
- {
- DSequence* aSeq = new DSequence();
- AddSeqToList( aSeq);
- }
-
-
- void DSeqDoc::FirstSelection( DSequence*& aSeq, long& start, long& nbases)
- {
- short left, right, top, bottom, atRow;
-
- start= nbases= atRow= 0;
- fAlnView->DeInstallEditSeq(); //?? reinstall after ?
- fAlnView->GetFirstSelectedCell(top,left);
- fAlnView->GetLastSelectedCell(bottom,right);
-
- if (left != DTableView::kNoSelection && top != DTableView::kNoSelection
- && (left != right || top != bottom)) {
- atRow = top;
- start = left; // - 1;
- nbases= right - start;
- }
- else if (fAlnIndex && fAlnIndex->IsSelected()) {
- fAlnIndex->GetFirstSelectedCell(top,left);
- fAlnIndex->GetLastSelectedCell(bottom,right);
- atRow= top;
- start= 0;
- nbases= 0; //key for all of seq
- }
-
- aSeq= fAlnView->SeqAt( atRow);
- if (aSeq) {
- aSeq->SetIndex(atRow);
- aSeq->SetSelection( start, nbases);
- }
- }
-
- void DSeqDoc::AddSeqAtToList( short aRow, long start1, long nbases1,
- DSeqList*& aSeqList, long& start, long& nbases)
- {
- DSequence* aSeq= fAlnView->SeqAt( aRow);
- if (aSeq) {
- /*--- ?? default is use all when nbases==0 !?
- if (wantAll) {
- start1= 0;
- nbases1= GethandleSize(aSeq->fBases);
- }
- ---*/
- aSeq->SetIndex( aRow);
- aSeq->SetSelection( start1, nbases1);
- aSeqList->InsertLast( aSeq);
- start= Max(start,start1);
- if (nbases==0) nbases= nbases1;
- else nbases= Min(nbases,nbases1);
- }
- }
-
- void DSeqDoc::GetSelection(Boolean equalCount, Boolean allAtNoSelection,
- DSeqList*& aSeqList, long& start, long& nbases)
- {
- short left, right, top, bottom, arow, acol;
- long start1, nbases1;
- Boolean wantAll;
-
- fAlnView->DeInstallEditSeq(); //?? reinstall after ?
- start= 0; start1= 0;
- nbases= 0; nbases1= 0;
- aSeqList= new DSeqList();
- fAlnView->GetFirstSelectedCell(top,left);
- fAlnView->GetLastSelectedCell(bottom,right);
-
- if (left != DTableView::kNoSelection && top != DTableView::kNoSelection
- && (left != right || top != bottom)) {
- wantAll= false;
- for (arow= top; arow<bottom; arow++) {
- if (equalCount) acol= left; else acol= 0;
- while (acol<right && !fAlnView->IsSelected(arow,acol)) acol++;
- start1= acol; // - 1;
- if (equalCount)
- while (acol<right && fAlnView->IsSelected(arow,acol)) acol++;
- else
- while (fAlnView->IsSelected(arow,acol)) acol++;
- nbases1= acol - start1;
- AddSeqAtToList( arow, start1, nbases1, aSeqList, start, nbases);
- }
- start = left; // - 1;
- nbases= right - start;
- }
-
- else if (fAlnIndex && fAlnIndex->IsSelected()) {
- fAlnIndex->GetFirstSelectedCell(top,left);
- fAlnIndex->GetLastSelectedCell(bottom,right);
- wantAll= true;
- for (arow= top; arow<bottom; arow++)
- AddSeqAtToList( arow, start1, nbases1, aSeqList, start, nbases);
- }
- else {
- wantAll= true;
- if (allAtNoSelection)
- for (arow= 0; arow<fAlnView->GetMaxRows(); arow++)
- AddSeqAtToList( arow, start1, nbases1, aSeqList, start, nbases);
- }
- }
-
-
- short DSeqDoc::SelectionToFile(Boolean AllatNoSelection, char* aFileName, short seqFormat)
- {
- long start, nbases;
- short nseqs;
- DSeqList *aSeqList;
-
- GetSelection( FALSE, AllatNoSelection, aSeqList, start, nbases);
- nseqs= aSeqList->GetSize();
- aSeqList->DoWrite( aFileName, seqFormat);
- delete aSeqList;
- return nseqs;
- }
-
-
-
-
- void DSeqDoc::WriteTo(DFile* aFile)
- {
- short outformat= DSeqFile::kGenBank;
- if (fFormatPop) outformat= fFormatPop->GetValue();
- fAlnView->DeInstallEditSeq(); //?? reinstall after ?
- if (fSaveSelection) {
- long start, nbases;
- DSeqList* aSeqList= NULL;
- fSaveSelection= false;
- GetSelection( FALSE, true, aSeqList, start, nbases);
- aSeqList->DoWrite( aFile, outformat);
- delete aSeqList;
- }
- else {
- fSeqList->ClearSelections(); //! make sure we write all of seq from this call !?
- fSeqList->DoWrite( aFile, outformat);
- this->NotDirty();
- }
- }
-
-
-
-
-
- #ifdef FIX_LATER
- /***********
- void DSeqDoc::AboutToSaveFile(TFile theSaveFile, CommandNumber itsCmd,
- Boolean VAR makingCopy) // override
- VAR
- Boolean needSameSize, sizesDiffer, isInterleaved;
- integer nseqs, err, format ;
- longint minbases;
- Handle aHand;
-
- void checkEqualSize( DSequence aSeq)
- longint var start, nbases;
- {
- //aSeq->GetSelection( start, nbases); << can still be set from fSelection or other old selecting command
- nBases= aSeq->fLength;
- if (minbases<0) then minbases= nbases
- else begin
- if (nbases!=minbases) then sizesDiffer= true;
- //- minbases= min( nbases, minbases);
- end();
- }
-
- {
- inherited::AboutToSaveFile(theSaveFile, itsCmd, makingCopy);
-
- if ((!fSaveSelection)) {
- //^^^^ !???? TAlnDoc will set this, always equal #bases????
- if (fFormatPop == NULL) format= kGenBank
- else format= fFormatPop->GetCurrentItem();
- needSameSize= false;
- isInterleaved= false;
- sizesDiffer= false;
- minbases= -1;
- nseqs= fSeqList->GetSize();
-
- if (nseqs>1)) // deal w/ one-per-file formats
- switch (format) {
- kGCG : format= kMSF;
- kStrider: format= kIG;
- kNoformat, kPlain, kUnknown: format= kGenbank;
- }
-
- fSeqList->ClearSelections(); //! make sure we write all of seq from this call !?
- fSeqList->Each( checkEqualSize);
-
- aHand= NewHandle(0);
- WriteSeqHeader( longint(aHand), TRUE, format, nseqs, minbases, gOutputName,
- needSameSize, isInterleaved); //<< need write for last two results
- aHand= DisposeIfHandle(aHand);
-
- if (((needSameSize || isInterleaved) && sizesDiffer)) {
- ParamText('all sequences must have same # bases for this format',
- ' Pick another format like Genbank or change selection.',
- 'WriteSeq','');
- Failure( -1, msgMyError);
- }
- }
- }
- **********/
- #endif
-
-
- Boolean DSeqDoc::ReadFrom(DFile* aFile, Boolean append) // revise for iostreams
- {
- if (!append) FreeData(); //?? or leave here for append...
- gDefSeqName= this->GetTitle(gDefSeqNameStore,sizeof(gDefSeqNameStore));
- fInFormat= DSeqFile::ReadSeqFile(aFile, fSeqList);
- return true; //?? (fInFormat != DSeqFile::kUnknown)
- }
-
-
-
- #if 0
- void DSeqDoc::Close() // override
- //must make sure all windows owned by ListDoc are closed 1st
-
- procedure closeSubwindows(TWindow aWind)
- begin
- // this is a subwindow !may not be owned by this doc
- if (!aWind->fClosesDocument) aWind->CloseAndFree();
- end();
-
- {
- ForAllWindowsDo(closeSubwindows);
- inherited::Close();
- }
-
- #endif
-
-
-
- void DSeqDoc::OpenSeqedWindow(DSequence* aSeq)
- {
- char* title= StrDup( aSeq->Name());
- StrExtendCat( &title, " Edit");
- DSeqedWindow* edwin = new DSeqedWindow( DSeqedWindow::kId, gApplication,
- this, aSeq, -5, -5, -50, -20, title);
- MemFree( title);
- edwin->Open();
- edwin->Select();
- }
-
-
-
- void DSeqDoc::EditSeqs()
- {
- DSequence* aSeq= fAlnView->SelectedSequence();
- if (aSeq) this->OpenSeqedWindow(aSeq);
-
- #if 0
- aCell : GridCell;
- count : integer;
-
- pascal void newEditWindow( integer anItem)
- TSequence VAR aSeq;
- {
- aSeq= TSequence(this->fSeqList->At(anItem));
- if ((aSeq!=NULL) && (count<kMaxOpenSeqed)) {
- this->OpenSeqedWindow(aSeq);
- count= count+1;
- }
- }
-
-
- if ((fAlnIndex=NULL) || (fAlnIndex.firstSelectedItem == 0))
- //nada
-
- else if (editOnly
- || (fAlnIndex.FirstSelectedItem == fAlnIndex->LastSelectedItem())) {
- count= 0;
- fAlnIndex->EachSelectedItemDo( newEditWindow);
- }
- #endif
- }
-
-
-
-
- void DSeqDoc::ToTextDoc()
- {
- #if 1
- DTempFile* tmpFile= new DTempFile();
- this->WriteTo(tmpFile);
- DRichTextDoc* doc= new DRichTextDoc(0, true, gTextFont);
- doc->Open(tmpFile);
- delete tmpFile;
- #else
- Nlm_ParData paratabs = {false, false, false, false, true, 0, 0}; // tabs==tabs
- char *txt = NULL;
- Nlm_ColData* cols= NULL;
- Nlm_ParData* para= ¶tabs;
-
- ulong txtsize = 0;
- DTempFile* tmpFile= new DTempFile();
- this->WriteTo(tmpFile);
- txt= tmpFile->ReadIntoMemory(txtsize);
- delete tmpFile;
-
- if (txt) {
- char name[256];
- StrCpy(name,"Text of ");
- long len= StrLen(name);
- //char *namep= name + len;
- (void) this->GetTitle( name + len, 256 - len);
- DWindow* aWin= new DWindow( 0, gApplication, document, -1, -1, -10, -10, name);
- DTextDocPanel* aDoc= new DTextDocPanel( 0, aWin, 500, 300);
- aDoc->SetResize( DView::matchsuper, DView::relsuper);
- aDoc->SetSlateBorder( false);
- aDoc->SetTabs( gTextTabStops);
- aDoc->Append( txt, para, cols, gTextFont);
- aWin->Open();
- aDoc->SizeToSuperview( aWin, true, false);
- }
- #endif
- }
-
-
- void DSeqDoc::MakeSeqPrint(Boolean doREMap)
- {
- long firstbase, nbases;
- DSeqList* aSeqList= NULL;
- fSaveSelection= false;
- DWindow * aDoc;
-
- GetSelection( true, true, aSeqList, firstbase, nbases);
- if (!aSeqList)
- return;
- else if (doREMap) {
- aDoc = new DREMapPrintDoc( DSeqPrintDoc::kSeqPrintDoc, this, aSeqList, firstbase, nbases);
- aDoc->Open();
- }
- else if (aSeqList->GetSize() > 1) {
- aDoc = new DAlnPrintDoc( DSeqPrintDoc::kSeqPrintDoc, this, aSeqList, firstbase, nbases);
- aDoc->Open();
- }
- else {
- aDoc = new DSeqPrintDoc( DSeqPrintDoc::kSeqPrintDoc, this, aSeqList, firstbase, nbases);
- aDoc->Open();
- }
- fPrintDoc= aDoc;
- }
-
- void DSeqDoc::MakeAlnPrint()
- {
- MakeSeqPrint(false);
- }
-
-
-
- void DSeqDoc::SetUpMenu(short menuId, DMenu*& aMenu)
- {
- //DWindow::SetUpMenu(menuId, aMenu);
-
- if (menuId == kSeqMenu) {
- if (!aMenu) aMenu = gApplication->NewMenu( menuId, "Sequence");
- //aMenu->AddItem( cSeqPrefs, "Seq Prefs...");
-
- aMenu->AddItem( cNewSeq, "New sequence");
- aMenu->AddItem( cEditSeq, "Edit seq...");
-
- DMenu* vMenu= new DSubMenu( kViewKindMenu, aMenu, "View seqs");
- vMenu->AddItem( kViewByDefault, "default");
- vMenu->AddItem( kViewByDate, "by Date");
- vMenu->AddItem( kViewBySize, "by Size");
- vMenu->AddItem( kViewByName, "by Name");
- vMenu->AddItem( kViewByKind, "by Kind");
- vMenu->AddItem( kViewAsText, "as Text");
-
- DMenu* mMenu= new DSubMenu( kSeqMaskMenu, aMenu, "Seq masks");
- mMenu->AddItem(cMaskSelAll,"Select all",false, true);
- mMenu->AddItem(cMaskInvert,"Invert selection",false, true);
- mMenu->AddItem(cMaskClear,"Clear selection",false, true);
- mMenu->AddSeparator();
- mMenu->AddItem(cMaskSelCommon,"Select consensus",false, true);
- //gViewCentral->DisableView(cMaskSelCommon);
- mMenu->AddItem(cMaskSelORF,"Select ORFs",false, true);
- //gViewCentral->DisableView(cMaskSelORF);
-
- aMenu->AddSeparator();
- aMenu->AddItem( cRevSeq, "Reverse");
- aMenu->AddItem( cCompSeq, "Complement");
- aMenu->AddItem( cRevCompSeq, "Rev-Compl");
- aMenu->AddItem( cDna2Rna, "Dna->Rna");
- aMenu->AddItem( cRna2Dna, "Rna->Dna");
- aMenu->AddItem( cToUpper, "UPPER Case");
- aMenu->AddItem( cToLower, "lower Case");
-
- aMenu->AddItem( cDegap, "Degap");
- aMenu->AddItem( cLockIndels, "Lock indels");
- aMenu->AddItem( cUnlockIndels, "Unlock indels");
- aMenu->AddItem( cConsensus, "Consensus");
- aMenu->AddItem( cTranslate, "Translate");
-
- aMenu->AddSeparator();
- aMenu->AddItem( cPrettyPrint, "Pretty Print...");
- aMenu->AddItem( cREMap, "Restriction map...");
- aMenu->AddItem( cDotPlot, "Dot plot...");
- gViewCentral->DisableView(cDotPlot);
-
- aMenu->AddSeparator();
- aMenu->AddItem( cNAcodes, "Nucleic codes...");
- aMenu->AddItem( cAAcodes, "Amino codes...");
- }
-
- else if (menuId == DApplication::cEditMenu) {
- aMenu->AddSeparator();
- aMenu->AddItem(DApplication::kFind,"Find.../F",false, true);
- aMenu->AddItem(DApplication::kFindAgain,"Find again/G",false, true);
- aMenu->AddItem(cFindORF,"Find ORF/R",false, true);
-
- }
-
- else if (menuId == kInternetMenu) {
- if (!aMenu) aMenu = gApplication->NewMenu( menuId, "Internet");
- aMenu->AddItem( cNCBIfetch, "NCBI fetch...");
- aMenu->AddItem( cNCBIblast, "NCBI BLAST search...");
- aMenu->AddItem( cEMBLfetch, "EMBL fetch...");
- aMenu->AddItem( cEMBLquicks, "EMBL Quicksearch...");
- aMenu->AddItem( cEMBLfasta, "EMBL FastA search...");
- aMenu->AddItem( cEMBLblitz, "EMBL Blitz search...");
- aMenu->AddItem( cFHCRCfetch, "FHCRC fetch...");
- aMenu->AddItem( cFHCRCblocks, "FHCRC Blocks search...");
- aMenu->AddItem( cGeneidSearch, "Geneid search...");
- aMenu->AddItem( cGrailSearch, "Grail search...");
- //aMenu->AddItem( cGenmarkSearch, "Genmark search...");
- //aMenu->AddItem( cPythiaSearch, "Pythia search...");
- aMenu->AddSeparator();
- }
-
- }
-
-
-
- #if 0
- char* DSeqDoc::GetTitle(char* title, ulong maxsize)
- {
- if (title==NULL) title= (char*) MemNew(maxsize);
- kUntitled
- Nlm_GetTitle( fNlmObject, title, maxsize);
- return title;
- }
- #endif
-
-
- char* DSeqDoc::GetTitle(char* title, ulong maxsize)
- {
- if (fSaveSelection) {
- if (title==NULL) title= (char*) MemNew(maxsize);
- DWindow::GetTitle( title, maxsize);
- #ifdef OS_DOS
- DFileManager::ReplaceSuffix( title, maxsize, ".sel");
- #else
- StrNCat( title,".part", maxsize);
- #endif
- return title;
- }
- else if (fDocTitle && *fDocTitle) {
- if (title==NULL) {
- maxsize= Min(maxsize,StrLen(fDocTitle)+1);
- title= (char*) MemNew(maxsize);
- }
- StrNCpy(title,fDocTitle,maxsize);
- return title;
- }
- else {
- DWindow::GetTitle( title, maxsize);
- //if (StringCmp(title,kUntitled)==0) *title= 0; // set to null so saveas is called
- return title;
- }
- }
-
- void DSeqDoc::FindORF()
- {
- long start, stop;
- DSequence* aSeq;
- short selrow;
- Nlm_RecT selr;
-
- aSeq= fAlnView->SelectedSequence(selrow);
- if (aSeq) {
- selr= fAlnView->GetSelRect();
- if (selr.right > selr.left+1) selr.left++; // !? offset sel start so we can repeat call
- selr.top= selrow;
- selr.bottom= selrow+1;
- aSeq->SetSelection( selr.left, 0);
- aSeq->SearchORF( start, stop);
- if (start>=0) {
- if (stop<start) stop= aSeq->LengthF(); //??
- aSeq->SetSelection( start, stop - start);
- selr.left= start;
- selr.right= stop;
- fAlnView->SelectCells( selr);
- }
- }
- }
-
-
- void DSeqDoc::MakeConsensus()
- {
- long firstBase = 0, nBases = 0;
- DSeqList * aSeqList= NULL;
- DSequence* cons;
-
- GetSelection( true, true, aSeqList, firstBase, nBases);
- if (aSeqList) {
- cons= fSeqList->Consensus();
- if (cons) {
- short aRow, totalRows;
- Nlm_RecT r;
- aRow= fSeqList->GetIdentityItemNo( cons);
- totalRows= fSeqList->GetSize();
- fSeqList->Delete(cons);
- delete cons;
- fAlnView->GetRowRect( aRow, r, totalRows-aRow+1);
- fAlnView->InvalRect( r);
- if (fAlnIndex) {
- fAlnIndex->GetRowRect( aRow, r, totalRows-aRow+1);
- fAlnIndex->InvalRect( r);
- }
- fAlnView->UpdateSize();
- }
-
- aSeqList->MakeConsensus();
- cons= aSeqList->Consensus();
- if (cons) {
- AddSeqToList( cons);
- //if (fAlnIndex) fAlnIndex->SelectCells( fSeqList->ConsensusRow(), 0);
- //fAlnIndex->ScrollSelectionIntoView(TRUE);
- }
- delete aSeqList;
- }
- }
-
-
- #if NETBLAST
- extern "C" short CallNCBIBlastService( char* blastProgram, char* blastDatabase, char* blastOptions,
- char* fastaInputFile, char* outputFile );
-
- void DSeqDoc::BLASTdialog()
- {
- char* blastProgram = "blastn";
- char* blastDatabase = "nr";
- char* blastOptions = NULL;
- char* fastaInputFile = "spup-blast-input.fasta";
- char* outputFile = "spup-blast-result.text";
- char instore[128];
- char outstore[128];
- DFile aFile;
-
- fastaInputFile= DFileManager::TempFilename( instore);
- outputFile= DFileManager::TempFilename( outstore);
-
- short nseq= SelectionToFile( false, fastaInputFile, DSeqFile::kPearson);
- if (nseq) {
- short err= CallNCBIBlastService(blastProgram, blastDatabase, blastOptions,
- fastaInputFile, outputFile);
-
- if (err) {
- Message(MSG_OK,"DSeqDoc::CallNCBIBlastService error %d", err);
- }
- else {
- DRichTextDoc* doc= new DRichTextDoc(0, true, gTextFont);
- doc->Open(outputFile);
- aFile.Initialize(outputFile);
- aFile.Delete();
- }
- }
- aFile.Initialize(fastaInputFile);
- aFile.Delete();
- }
- #endif
-
-
- Boolean DSeqDoc::DoMenuTask(long tasknum, DTask* theTask)
- {
- DWindow* win = NULL;
-
- switch (tasknum) {
-
- case cNewSeq :
- AddNewSeqToList();
- //fall into EditSeqs
- case cEditSeq:
- EditSeqs();
- return true;
-
- case cSaveSel:
- fSaveSelection= true;
- gApplication->DoMenuTask( DApplication::kSaveAs, NULL);
- fSaveSelection= false;
- return true;
-
- case cFindORF:
- FindORF();
- return true;
-
- case cConsensus:
- MakeConsensus();
- return true;
-
- case cRevSeq:
- case cCompSeq:
- case cRevCompSeq:
- case cDna2Rna:
- case cRna2Dna:
- case cToUpper:
- case cToLower:
- case cDegap:
- case cLockIndels:
- case cUnlockIndels:
- case cTranslate:
- {
- long firstBase = 0, nBases = 0;
- DSeqList * aSeqList= NULL;
- DSeqChangeCmd * cmd = NULL;
-
- //fAlnView->DeInstallEditSeq(); //?? reinstall after ?
- GetSelection( TRUE, TRUE, aSeqList, firstBase, nBases);
- switch (tasknum) {
- case cRevSeq : cmd= new DSeqReverseCmd( this, fAlnView, aSeqList); break;
- case cCompSeq : cmd= new DSeqComplementCmd( this, fAlnView,aSeqList); break;
- case cRevCompSeq: cmd= new DSeqRevComplCmd( this, fAlnView,aSeqList); break;
- case cDna2Rna : cmd= new DSeqDna2RnaCmd( this, fAlnView,aSeqList); break;
- case cRna2Dna : cmd= new DSeqRna2DnaCmd( this, fAlnView,aSeqList); break;
- case cToUpper : cmd= new DSeqUppercaseCmd( this, fAlnView,aSeqList); break;
- case cToLower : cmd= new DSeqLowercaseCmd( this,fAlnView, aSeqList); break;
- case cDegap : cmd= new DSeqCompressCmd( this, fAlnView,aSeqList); break;
- case cLockIndels: cmd= new DSeqLockIndelsCmd( this, fAlnView,aSeqList); break;
- case cUnlockIndels: cmd= new DSeqUnlockIndelsCmd( this, fAlnView,aSeqList); break;
- case cTranslate : cmd= new DSeqTranslateCmd( this, fAlnView,aSeqList); break;
-
- default:
- delete aSeqList;
- Message(MSG_OK,"DSeqDoc::method not ready.");
- return true;
-
- }
- if (cmd) {
- if (cmd->Initialize()) PostTask( cmd);
- else {
- delete cmd;
- Message(MSG_OK,"DSeqDoc::method failed.");
- }
- }
- return true;
- }
-
- case cPrettyPrint: MakeSeqPrint( false); return true; //MakeAlnPrint();
- case cREMap: MakeSeqPrint( true); return true;
- case cNAcodes: NucCodesPicture(); return true;
- case cAAcodes: AminoCodesPicture(); return true;
- case cDotPlot: //MakeDottyPlot(); return true;
- Message(MSG_OK,"DSeqDoc::method not ready.");
- return true;
-
- #if NETBLAST
- case cNCBIblast:
- {
- char* blastProgram = "blastn";
- char* blastDatabase = "nr";
- char* blastOptions = NULL;
- char* fastaInputFile = "spup-blast-input.fasta";
- char* outputFile = "spup-blast-result.text";
- char instore[128];
- char outstore[128];
- DFile aFile;
-
- fastaInputFile= DFileManager::TempFilename( instore);
- outputFile= DFileManager::TempFilename( outstore);
-
- short nseq= SelectionToFile( false, fastaInputFile, DSeqFile::kPearson);
- if (nseq) {
- short err= CallNCBIBlastService(blastProgram, blastDatabase, blastOptions,
- fastaInputFile, outputFile);
-
- if (err) {
- Message(MSG_OK,"DSeqDoc::CallNCBIBlastService error %d", err);
- }
- else {
- DRichTextDoc* doc= new DRichTextDoc(0, true, gTextFont);
- doc->Open(outputFile);
- aFile.Initialize(outputFile);
- aFile.Delete();
- }
- }
- aFile.Initialize(fastaInputFile);
- aFile.Delete();
- }
- return true;
-
- #else
- case cNCBIblast:
- #endif
-
- case cGrailSearch:
- case cGeneidSearch:
- case cFHCRCblocks:
- case cEMBLfasta:
- case cEMBLblitz:
- case cEMBLquicks:
- {
- DSequence* aSeq= fAlnView->SelectedSequence();
- if (aSeq) {
- switch (tasknum) {
- case cNCBIblast: win= new DNCBIBlast(0, this, aSeq); break;
- case cEMBLblitz: win= new DEMBLBlitz(0, this, aSeq); break;
- case cEMBLfasta: win= new DEMBLFasta(0, this, aSeq); break;
- case cEMBLquicks: win= new DEMBLQuicks(0, this, aSeq); break;
- case cFHCRCblocks: win= new DFHCRCblocks(0, this, aSeq); break;
- case cGeneidSearch: win= new DUWFGeneID(0, this, aSeq); break;
- case cGrailSearch: win= new DORNLGrail(0, this, aSeq); break;
- }
- if (win) win->Open();
- }
- return true;
- }
-
- case cFHCRCfetch:
- case cEMBLfetch:
- case cNCBIfetch:
- switch (tasknum) {
- case cNCBIfetch: win= new DNCBIFetch(0, this); break;
- case cEMBLfetch: win= new DEMBLFetch(0, this); break;
- case cFHCRCfetch: win= new DFHCRCfetch(0, this); break;
- }
- if (win) win->Open();
- return true;
-
- case cGenmarkSearch:
- case cPythiaSearch:
- Message(MSG_OK,"DSeqDoc::method not ready.");
- return true;
-
-
- default:
- return DTaskMaster::DoMenuTask(tasknum, theTask);
- }
-
- }
-
-
- Boolean DSeqDoc::IsMyAction(DTaskMaster* action)
- {
- long menuid= 0, menuitem = action->Id();
- if (action->fSuperior) menuid = action->fSuperior->Id();
-
- //if (menuid == DApplication::cEditMenu)
- switch (menuitem) {
-
- case DApplication::kCut:
- case DApplication::kCopy:
- case DApplication::kClear:
- {
- DAlnEditCommand* cmd= new DAlnEditCommand(this, menuitem);
- PostTask( cmd);
- return true;
- }
-
- case DApplication::kPaste:
- {
- DView* clipview= (DView*) gClipboardMgr->fClipView; // GetClipView();
- if (clipview && clipview->fKind == DAlnView::kindAlnView) {
- DAlnPasteCommand* cmd= new DAlnPasteCommand(this);
- PostTask( cmd);
- return true;
- }
- else if (HasEditText()) { /* && clipview->fKind == OStype("TEXT") */
- if (fEditText->IsMyAction(action)) return true;
- }
- return true; //?? always handle this message?
- }
-
- case DApplication::kSelectAll:
- if (fAlnIndex) {
- Nlm_RecT r;
- Nlm_LoadRect(& r, 0, 0, 1/*fAlnIndex->GetMaxCols()*/, fAlnIndex->GetMaxRows());
- fAlnIndex->SelectCells( r);
- return true;
- }
-
- }
-
-
- if (menuid == kViewKindMenu)
- switch (menuitem) {
- case kViewByDefault:
- this->SortView(DSeqList::kSortByItem); return true;
- case kViewByDate:
- this->SortView(DSeqList::kSortByDate); return true;
- case kViewBySize:
- this->SortView(DSeqList::kSortBySize); return true;
- case kViewByName:
- this->SortView(DSeqList::kSortByName); return true;
- case kViewByKind:
- this->SortView(DSeqList::kSortByKind); return true;
- case kViewAsText:
- this->ToTextDoc(); return true;
- default: return true;
- }
-
- #if MASKS
- else if (menuid == kSeqMaskMenu && fAlnView->fMaskLevel>0) {
- long iseq, nseq= fSeqList->GetSize();
- switch (menuitem) {
-
- case cMaskSelCommon:
- fAlnView->HiliteCommonBases();
- return true;
-
- case cMaskSelORF:
- fAlnView->HiliteORFs();
- return true;
-
- case cMaskSelAll:
- for (iseq= 0; iseq<nseq; iseq++)
- fSeqList->SeqAt(iseq)->SetMask(fAlnView->fMaskLevel);
- fAlnView->Invalidate();
- return true;
-
- case cMaskInvert:
- for (iseq= 0; iseq<nseq; iseq++)
- fSeqList->SeqAt(iseq)->FlipMask(fAlnView->fMaskLevel);
- fAlnView->Invalidate();
- return true;
-
- case cMaskClear:
- for (iseq= 0; iseq<nseq; iseq++)
- fSeqList->SeqAt(iseq)->ClearMask(fAlnView->fMaskLevel);
- fAlnView->Invalidate();
- return true;
-
- default:
- return true;
- }
- }
- #endif
-
-
- else if (menuid == DSeqApps::kChildMenu)
- switch (menuitem) {
- #if 0
- case cAddChildCmd:
- case cRemoveChildCmd:
- DoMenuTask(menuitem);
- break;
- #endif
- default:
- {
- long firstBase = 0, nBases = 0;
- DSeqList * aSeqList= NULL;
- //fAlnView->DeInstallEditSeq(); //?? reinstall after ?
- GetSelection( TRUE, TRUE, aSeqList, firstBase, nBases);
- DSeqApps::CallChildApp( menuitem, aSeqList);
- if (aSeqList) delete aSeqList;
- }
- break;
- }
-
- else if (menuitem == kColorButHit) {
- fUseColor= ((DView*)action)->GetStatus();
- fAlnView->Invalidate();
- return true;
- }
- else if (menuitem == kLockButHit) {
- fAlnView->SetTextLock( ((DView*)action)->GetStatus());
- return true;
- }
-
- #if MASKS
- else if (menuitem == kModePopup) {
- short mode= fModePop->GetValue();
- #if 1
- fAlnView->SetViewMode( mode);
- #else
- switch (mode) {
- case DAlnView::kModeSlide:
- fAlnView->SetTextLock( true);
- if (fAlnView->fMaskLevel>0) fAlnView->Invalidate();
- fAlnView->fMaskLevel= 0;
- break;
- case DAlnView::kModeEdit:
- fAlnView->SetTextLock( false);
- if (fAlnView->fMaskLevel>0) fAlnView->Invalidate();
- fAlnView->fMaskLevel= 0;
- break;
- case DAlnView::kModeMask1:
- case DAlnView::kModeMask2:
- case DAlnView::kModeMask3:
- case DAlnView::kModeMask4: {
- fAlnView->SetTextLock( true);
- fAlnView->fMaskLevel= mode - DAlnView::kModeMask1 + 1;
- fAlnView->Invalidate();
- short i, nseq= fSeqList->GetSize();
- for (i=0; i<nseq; i++) fSeqList->SeqAt(i)->FixMasks();
- }
- break;
- }
- #endif
- return true;
- }
- #endif
-
- else
- return DoMenuTask(menuitem, NULL);
-
- return false;
- }
-
-
-
-
-