/***************************************************************************** # Copyright (C) 1994-2008 by David Gordon. # All rights reserved. # # This software is part of a beta-test version of the Consed/Autofinish # package. It should not be redistributed or # used for any commercial purpose, including commercially funded # sequencing, without written permission from the author and the # University of Washington. # # This software is provided ``AS IS'' and any express or implied # warranties, including, but not limited to, the implied warranties of # merchantability and fitness for a particular purpose, are disclaimed. # In no event shall the authors or the University of Washington be # liable for any direct, indirect, incidental, special, exemplary, or # consequential damages (including, but not limited to, procurement of # substitute goods or services; loss of use, data, or profits; or # business interruption) however caused and on any theory of liability, # whether in contract, strict liability, or tort (including negligence # or otherwise) arising in any way out of the use of this software, even # if advised of the possibility of such damage. # # Building Consed from source is error prone and not simple which is # why I provide executables. Due to time limitations I cannot # provide any assistance in building Consed. Even if you do not # modify the source, you may introduce errors due to using a # different version of the compiler, a different version of motif, # different versions of other libraries than I used, etc. For this # reason, if you discover Consed bugs, I can only offer help with # those bugs if you first reproduce those bugs with an executable # provided by me--not an executable you have built. # # Modifying Consed is also difficult. Although Consed is modular, # some modules are used by many other modules. Thus making a change # in one place can have unforeseen effects on many other features. # It may takes months for you to notice these other side-effects # which may not seen connected at all. It is not feasable for me to # provide help with modifying Consed sources because of the # potentially huge amount of time involved. # #*****************************************************************************/ #include "guiChoiceOfSeqMatches.h" #include "handleWindowManagerDelete2.h" #include #include #include #include #include "hp_exception_kludge.h" #include "assemblyView.h" #include "abs.h" #include "contig.h" #include "popupErrorMessage2.h" #include "compareContigs.h" #include "consed.h" static void cbUserPushedDismissButton( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiChoiceOfSeqMatches* pGuiChoiceOfSeqMatches = (guiChoiceOfSeqMatches*) pClientData; TRY_CATCH_WRAPPER( delete pGuiChoiceOfSeqMatches; ); } static void cbShowAlignment( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiChoiceOfSeqMatches* pGuiChoiceOfSeqMatches = (guiChoiceOfSeqMatches*) pClientData; TRY_CATCH_WRAPPER( pGuiChoiceOfSeqMatches->userWantsToShowAlignment( wid, (XmListCallbackStruct*) pCallData) ); } const int nWidthInChars = 100; void guiChoiceOfSeqMatches :: createWindow() { Dimension dimHeight; Position nY; Position nX; XtVaGetValues( pAssemblyView_->widPopupShell_, XmNheight, &dimHeight, XmNy, &nY, XmNx, &nX, NULL ); widPopupShell_ = XtVaCreatePopupShell( "guiChoiceOfSeqMatches", topLevelShellWidgetClass, pAssemblyView_->widPopupShell_, XmNtitle, "Sequence Matches", XmNnoResize, False, XmNautoUnmanage, False, XmNtransient, False, XmNdeleteResponse, XmDO_NOTHING, XmNy, nY + dimHeight, XmNx, nX, NULL ); handleWindowManagerDelete2( widPopupShell_, cbUserPushedDismissButton, this ); Widget widForm = XtVaCreateManagedWidget( "form", xmFormWidgetClass, widPopupShell_, XmNshadowThickness, 0, XmNborderWidth, 0, NULL ); RWCString soHeadings = "copy copy size similarity"; soHeadings += "\n 1 2 "; Widget widHeadings = XtVaCreateManagedWidget( "headings", xmTextWidgetClass, widForm, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 0, XmNrows, 2, XmNeditable, False, XmNcursorPositionVisible, False, XmNtraversalOn, False, XmNvalue, soHeadings.data(), XmNeditMode, XmMULTI_LINE_EDIT, XmNcolumns, nWidthInChars, NULL ); Widget widConnectToAbove = widHeadings; widShowAlignmentButton_ = XtVaCreateManagedWidget( "Show Alignment", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNtraversalOn, False, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 10, // XmNrightAttachment, XmATTACH_POSITION, // XmNrightPosition, 40, NULL ); XtAddCallback( widShowAlignmentButton_, XmNactivateCallback, cbShowAlignment, this ); widDismissButton_ = XtVaCreateManagedWidget( "Dismiss", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNtraversalOn, False, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 90, NULL ); XtAddCallback( widDismissButton_, XmNactivateCallback, cbUserPushedDismissButton, this ); Widget widConnectToBelow = widDismissButton_; int nArgs = 0; Arg aArg[500]; XtSetArg( aArg[nArgs], XmNselectionPolicy, XmSINGLE_SELECT ); nArgs++; XtSetArg( aArg[nArgs], XmNtopAttachment, XmATTACH_WIDGET ); nArgs++; XtSetArg( aArg[nArgs], XmNtopWidget, widConnectToAbove ); nArgs++; XtSetArg( aArg[nArgs], XmNbottomAttachment, XmATTACH_WIDGET ); ++nArgs; XtSetArg( aArg[nArgs], XmNbottomWidget, widConnectToBelow ); nArgs++; XtSetArg( aArg[nArgs], XmNleftAttachment, XmATTACH_FORM ); nArgs++; XtSetArg( aArg[nArgs], XmNrightAttachment, XmATTACH_FORM ); nArgs++; XtSetArg( aArg[nArgs], XmNmarginWidth, 0); nArgs++; XtSetArg( aArg[nArgs], XmNmarginHeight, 0); nArgs++; XtSetArg( aArg[nArgs], XmNtextColumns, nWidthInChars ); nArgs++; XtSetArg( aArg[nArgs], XmNvisibleItemCount, 10 ); nArgs++; widScrolledList_ = XmCreateScrolledList( widForm, "list", aArg, nArgs ); XtManageChild( widScrolledList_ ); XtAddCallback( widScrolledList_, XmNdefaultActionCallback, cbShowAlignment, this ); XtPopup( widPopupShell_, XtGrabNone ); } void guiChoiceOfSeqMatches :: raiseWindow() { XtMapWidget( widPopupShell_ ); XRaiseWindow( XtDisplay( widPopupShell_ ), XtWindow( widPopupShell_ ) ); } void guiChoiceOfSeqMatches :: loadWindowWithClickedSeqMatches() { RWCString soMessage( (size_t) 2000 ); XmStringTable ppXtStringClickedSeqMatches = (XmStringTable) XtMalloc( pAssemblyView_->aClickedSeqMatches_.length() * sizeof( XmString ) ); int nSeqMatch; for( nSeqMatch = 0; nSeqMatch < pAssemblyView_->aClickedSeqMatches_.length(); ++nSeqMatch ) { seqMatch* pSeqMatch = pAssemblyView_->aClickedSeqMatches_[ nSeqMatch ]; soMessage = ""; for( int nCopy = 0; nCopy <= 1; ++nCopy ) { soMessage += pSeqMatch->pContig_[ nCopy ]->soGetName(); soMessage += " "; RWCString soNumbers( (size_t) 100 ); soNumbers.appendFormat( "%d-%d", pSeqMatch->nUnpaddedStartConsPos_[nCopy], pSeqMatch->nUnpaddedEndConsPos_[nCopy] ); soMessage.increaseMaxLengthIfNecessary( 30 ); soMessage.appendFormat( "%14s", soNumbers.data() ); if ( nCopy == 0 ) { soMessage += " to "; } } if ( pSeqMatch->bComplemented_ ) soMessage += " (comp)"; else soMessage += " (not comp)"; soMessage.increaseMaxLengthIfNecessary( 30 ); soMessage.appendFormat( " %d %4.1f", ABS( pSeqMatch->nUnpaddedEndConsPos_[1] - pSeqMatch->nUnpaddedStartConsPos_[1] ), pSeqMatch->fPercentSimilar_ ); ppXtStringClickedSeqMatches[ nSeqMatch ] = XmStringCreateLocalized( soMessage.data() ); } // for( int nSeqMatch = 0; XtVaSetValues( widScrolledList_, XmNitems, ppXtStringClickedSeqMatches, XmNitemCount, pAssemblyView_->aClickedSeqMatches_.length(), NULL ); // clean up memory for( nSeqMatch = 0; nSeqMatch < pAssemblyView_->aClickedSeqMatches_.length(); ++nSeqMatch ) { XmStringFree( ppXtStringClickedSeqMatches[ nSeqMatch ] ); } XtFree( (char*) ppXtStringClickedSeqMatches ); } void guiChoiceOfSeqMatches :: userWantsToShowAlignment( Widget widCallback, XmListCallbackStruct* pXmListCallbackStruct ) { assert( ( widCallback == widShowAlignmentButton_ ) || ( widCallback == widScrolledList_ ) ); int nIndex; if ( widCallback == widScrolledList_ ) { nIndex = pXmListCallbackStruct->item_position; } else { // which item is selected? int* pSelectedPositions; int nNumberOfItemsSelected; if ( XmListGetSelectedPos( widScrolledList_, &pSelectedPositions, &nNumberOfItemsSelected ) ) { assert( nNumberOfItemsSelected == 1 ); nIndex = pSelectedPositions[0]; } else { // nothing was selected popupErrorMessage2( widPopupShell_, "You must first select a line in the list before clicking on \"Show Alignment\"" ); return; } } // XmList returns 1-based indices. Convert to 0-based; --nIndex; seqMatch* pSeqMatch = pAssemblyView_->aClickedSeqMatches_[ nIndex ]; compareContigs* pCompareContigs = ConsEd::pGetConsEd()->pCreateCompareContigsForAssemblyView(); pCompareContigs->popupForAssemblyView( pSeqMatch ); } guiChoiceOfSeqMatches :: ~guiChoiceOfSeqMatches() { pAssemblyView_->pGuiChoiceOfSeqMatches_ = NULL; XtPopdown( widPopupShell_ ); XtDestroyWidget( widPopupShell_ ); }