Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gridPanel"></param>
        /// <param name="qm"></param>

        public static void DisplayData(
            MoleculeGridPanel gridPanel,
            QueryManager qm)
        {
            if (gridPanel == null)             // if grid panel not defined assume display is in normal results panel
            {
                gridPanel = SessionManager.Instance.QueryResultsControl.MoleculeGridPageControl.MoleculeGridPanel;
                QbUtil.SetMode(QueryMode.Browse);                 // put into browse mode
            }

            else if (gridPanel.Parent is PopupGrid)             // display in popup grid
            {
                PopupGrid pug = gridPanel.Parent as PopupGrid;
                pug.Initialize(qm);                 // be sure popup is initialized
                WindowsHelper.FitFormOnScreen(pug);
                pug.Show();
            }

            MoleculeGridControl grid = qm.MoleculeGrid;

            gridPanel.Visible = true;
            grid.Visible      = true;
            grid.DataSource   = qm.DataTable;           // set the datasource for the grid to the datatable

            RefreshDataDisplay(qm);
        }
Exemplo n.º 2
0
/// <summary>
/// Process queued command
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void Timer_Tick(object sender, EventArgs e)
        {
            string arg;
            int    i1;

            Timer.Stop();

            string cmd = CommandToExecute;

            if (String.IsNullOrEmpty(cmd))
            {
                return;
            }

            else if (MoleculeGridControl.IsShowContextMenuCommand(cmd, "ShowContextMenu:TargetContextMenu", out arg))
            {
                SelectedTarget = arg;
                Point ptCursor = Cursor.Position;
                ptCursor = PointToClient(ptCursor);
                TargetContextMenu.Show(ParentControl, ptCursor);                 // show on panel since events lost if on WebBrowser control
            }

            else if ((i1 = Lex.IndexOf(cmd, "ClickFunction")) >= 0)
            {
                cmd = cmd.Substring(i1 + "ClickFunction".Length + 1);                 // get function name
                ClickFunctions.Process(cmd, null);
            }

            else
            {
                CommandExec.ExecuteCommandAsynch(cmd);
            }

            return;
        }
Exemplo n.º 3
0
/// <summary>
/// Initialize the Preview Query and associated QueryManager and Grid View
/// </summary>

        public void InitializeView()
        {
            if (SwQuery != null)
            {
                return;
            }

            SwQuery = BuildStructureSearchQuery();
            DataTableMx dt = DataTableManager.BuildDataTable(SwQuery);

            Qm = ToolHelper.SetupQueryManager(SwQuery, dt);

            MoleculeGridPageControl mgpc = MoleculeGridPageControl;

            ToolHelper.SetupGridPanelForDisplay(Qm, mgpc.MoleculeGridPanel);

            MoleculeGridControl grid = mgpc.MoleculeGrid;

            if (grid != null && grid.GV != null)
            {
                grid.GV.IndicatorWidth = 40;                 // narrow indicator col a bit
            }
            ClearDataAndGrid();

            return;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Render the view by configuring the control for the current view settings
        /// </summary>

        public override void ConfigureRenderingControl()
        {
            if (Qm == null)
            {
                return;
            }

            MoleculeGridControl grid = GridPanel.SelectBaseGridViewGrid(Qm);

            Qm.LinkMember(grid);           // link grid into qm

            DataTableMx dt = Qm.DataTable; // save ref to data table

            grid.DataSource = null;        // clear source for header build
            Qm.DataTable    = dt;          // restore data table in qm

            grid.ShowCheckMarkCol = BaseQuery.ShowGridCheckBoxes;
            grid.FormatGridHeaders(Qm.ResultsFormat);      // qm.MoleculeGrid.V.Columns.Count should be set for proper cols
            grid.Visible = true;                           // now visible

            Qrc.MoleculeGridPageControl = GridPageControl; // link query results to this page

            GridPanel.SetDataSource(Qm, dt);

            ResultsFormatter fmtr = Qm.ResultsFormatter;

            if (fmtr != null && fmtr.FormattingStarted && !fmtr.BrowseExistingResults)              // if already formatting need to start grid display
            {
                grid.StartDisplay();
            }

            ConfigureCount++;
            return;
        }
Exemplo n.º 5
0
/// <summary>
/// Complete data retrieval
/// </summary>
/// <returns></returns>
        DialogResult CompleteRetrieval()
        {
            PrintingSystem         ps  = (PrintingSystem)Instance.PrintControl.PrintingSystem;
            PrintableComponentLink pcl = ps.Links[0] as PrintableComponentLink;

            DataTableManager dtm = Qm.DataTableManager;

            if (!dtm.RowRetrievalComplete)
            {                           // be sure we have the complete set of rows
                MoleculeGridControl mg = Qm.MoleculeGrid;
                Qm.MoleculeGrid = null; // don't update the grid itself
                DialogResult dr = dtm.CompleteRetrieval();
                Qm.MoleculeGrid = mg;

                if (dr == DialogResult.Cancel)
                {
                    return(dr);
                }
            }

            if (Qm.DataTable.Rows.Count != PreviewRowCount)
            {
                pcl.CreateDocument();                 // recreate the document with full set of rows
            }
            return(DialogResult.OK);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Free resources linked to this instance
        /// </summary>

        public void Dispose()
        {
            try
            {
                DisposeOfControls();

                if (Query != null)
                {
                    Query.FreeControlReferences();                                // just free control references
                }
                if (MoleculeGrid != null)
                {
                    MoleculeGrid.Dispose();
                }
                if (QueryEngine != null)
                {
                    QueryEngine.Dispose();
                }
                if (DataTableManager != null)
                {
                    DataTableManager.Dispose();
                }

                if (ResultsFormat != null)
                {
                    ResultsFormat.QueryManager = null;
                }
                if (ResultsFormatter != null)
                {
                    ResultsFormatter.QueryManager = null;
                }
                if (StatusBarManager != null)
                {
                    StatusBarManager.QueryManager = null;
                }
                if (QueryExec != null)
                {
                    QueryExec.QueryManager = null;
                }

                QueryResultsControl = null;
                Query            = null;
                DataTableManager = null;
                DataTable        = null;
                ResultsFormat    = null;
                ResultsFormatter = null;
                StatusBarManager = null;
                MoleculeGrid     = null;
                QueryExec        = null;
                QueryEngine      = null;
            }

            catch (Exception ex)
            {
                DebugLog.Message(DebugLog.FormatExceptionMessage(ex));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Build the Query, QueryManager and DataTable for the matching structure display
        /// </summary>

        public void BuildStructureDisplayQuery()
        {
            MetaTable mt = MetaTableCollection.Get("QuickSearchRelatedStructures");

            if (mt == null)
            {
                DebugLog.Message("QuickSearchRelatedStructures MetaTable not found");
                RSC.MoleculeGridPageControl.Visible = false;
                return;
            }

            Query      q  = ToolHelper.InitEmbeddedDataToolQuery(mt);
            QueryTable qt = q.Tables[0];

            q.UserObject.Name     = qt.MetaTable.Label;
            StructureDisplayQuery = q;

            QueryColumn qc = qt.FirstStructureQueryColumn;

            if (qc != null)             // setup dummy criteria
            {
                ParsedStructureCriteria pssc = new ParsedStructureCriteria();
                pssc.SearchType = StructureSearchType.FullStructure;                 // just full structure search for now
                pssc.Molecule   = new MoleculeMx(MoleculeFormat.Smiles, "C");        // placeholder structure
                pssc.ConvertToQueryColumnCriteria(qc);

                qc.DisplayFormatString = "Highlight=true;Align=true";
            }

            string title = "Related Structures";

            qt.Label = title;

            DataTableMx dt = q.ResultsDataTable as DataTableMx;

            Qm = ToolHelper.SetupQueryManager(q, dt);

            MoleculeGridPageControl mgpc = RSC.MoleculeGridPageControl;
            MoleculeGridPanel       gp   = mgpc.MoleculeGridPanel;

            mgpc.Width  = RSC.Width - 3;            // be sure we have page control correctly sized
            mgpc.Height = RSC.Height - mgpc.Top - 3;

            ToolHelper.SetupGridPanelForDisplay(Qm, mgpc.MoleculeGridPanel, true, true);

            MoleculeGridControl grid = mgpc.MoleculeGrid;

            if (grid != null && grid.GV != null)
            {
                grid.GV.IndicatorWidth = 40;                 // narrow indicator a bit
            }
            //ToolHelper.DisplayData // build and display empty grid for query with columns scaled to fit the grid
            //		(q, dt, RSC.MoleculeGridPageControl.MoleculeGridPanel, true, true);

            return;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Static method to show the grid
        /// </summary>
        /// <param name="grid"></param>

        public static void Show(MoleculeGridControl grid)
        {
            if (Instance == null)
            {
                Instance = new EditFind();
            }
            Instance.Grid = grid;
            if (Instance.Visible)
            {
                return;
            }

            Instance.FindText.Text = "";
            Instance.Progress.Text = "";
            Instance.Show(SessionManager.ActiveForm);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Setup the proper grid, banded or layout, based on the ResultsFormat setting
        /// </summary>

        internal MoleculeGridControl SelectBaseGridViewGrid(QueryManager qm)
        {
            MoleculeGridControl grid;

            //MoleculeGridPanel mgp = new MoleculeGridPanel(); // start with clean grids (not working for some reason)
            //mgp.Controls.Remove(mgp.LayoutViewGrid);
            //mgp.Controls.Remove(mgp.BandedViewGrid);
            //LayoutViewGrid = mgp.LayoutViewGrid;
            //BandedViewGrid = mgp.BandedViewGrid;

            if (qm == null || qm.ResultsFormat == null ||
                qm.ResultsFormat.UseBandedGridView)          // select grid with desired view
            {
                grid = BandedViewGrid;
            }

            else
            {
                grid = LayoutViewGrid;              // show layout form
            }
            Controls.Clear();

            if (grid == null)
            {
                return(null);
            }

            Controls.Add(grid);             // add the grid to the grid panel

            grid.Dock         = DockStyle.Fill;
            grid.QueryManager = qm;
            Grid = grid;

            if (qm != null)
            {
                qm.MoleculeGrid = grid;                 // link this grid into query manager
            }
            else
            {
                qm = qm;              // debug;
            }
            return(grid);
        }
Exemplo n.º 10
0
/// <summary>
/// Retrieval complete. Update cache and request display of values
/// </summary>
/// <param name="r"></param>

        void DepictionRetrievalComplete(IAsyncResult r)
        {
            try
            {
                QeGetAdditionalDataDelegate d = (r as AsyncResult).AsyncDelegate as QeGetAdditionalDataDelegate;

                DepictionRetrievalArgs a = r.AsyncState as DepictionRetrievalArgs;
                int i = SmallWorldData.GetSvgOptionsIndex(a.color, a.align);
                Status[i] = -Status[i];                 // set to negative to indicate complete

                string depictionsListString = d.EndInvoke(r) as string;
                SvgDict[i] = Deserialize(depictionsListString);
                int count = SvgDict[i].Count;

                if (Debug)
                {
                    DebugLog.Message("DepictionRetrievalComplete " + a.reqId + ", Current: " + (a.reqId == CurrentRequestId) +
                                     ", Count: " + count + ", Time: " + LogFile.FormatElapsedTimeInMs(a.startTime));
                }

                if (a.reqId == CurrentRequestId)                 // if latest request then display
                {
                    QueryManager        qm   = a.qm;
                    MoleculeGridControl grid = qm.MoleculeGrid;

                    if (grid.InvokeRequired)                     // use invoke if not on UI thread
                    {
                        grid.Invoke(new MethodInvoker(grid.RefreshDataSourceMx));
                    }

                    else
                    {
                        grid.RefreshDataSourceMx();
                    }
                }
            }
            catch (Exception ex)
            {
                DebugLog.Message("DepictionRetrievalComplete exception: " + DebugLog.FormatExceptionMessage(ex));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Dispose
        /// </summary>

        public new void Dispose()
        {
            ResultsPage = null;
            PageControl = null;
            View        = null;
            Grid        = null;

            if (LayoutViewGrid != null)
            {
                LayoutViewGrid.Dispose();
            }

            if (BandedViewGrid != null)
            {
                BandedViewGrid.Dispose();
            }

            base.Dispose();

            return;
        }
Exemplo n.º 12
0
        public bool ProcessInternal(
            WebBrowserNavigatingEventArgs e,
            Control parentControl)
        {
            string url, arg;

            url = e.Url.ToString();

            ParentControl = parentControl;             // panel to attach menu to

            if (!Lex.Contains(url, "mobius/command"))
            {
                return(false);
            }

            int i1 = url.IndexOf("?");

            if (i1 < 0)
            {
                return(false);
            }
            string cmd = url.Substring(i1 + 1);

            cmd = cmd.Replace("%20", " ");             // todo: more complete translation
            Lex lex = new Lex();

            lex.OpenString(cmd);

            if (MoleculeGridControl.IsShowContextMenuCommand(cmd, "ShowContextMenu:MetaTableLabelContextMenu", out arg))
            {
                SetupTableHeaderPopup(cmd, menuShowDescription, out ShowDescriptionArg,
                                      menuAddToQuery, out AddToQueryArg);
                Point ptCursor = Cursor.Position;
                ptCursor = parentControl.PointToClient(ptCursor);
                MetaTableLabelContextMenu.Show(parentControl, ptCursor);                       // show on panel since events lost if on WebBrowser control

                while (MetaTableLabelContextMenu != null && MetaTableLabelContextMenu.Visible) // keep this visible as long as popup is visible
                {
                    System.Threading.Thread.Sleep(250);
                    Application.DoEvents();
                }
            }

            else if (MoleculeGridControl.IsShowContextMenuCommand(cmd, "ShowContextMenu:CompoundIdContextMenu", out arg))
            {
                SelectedCid = arg;
                Point ptCursor = Cursor.Position;
                ptCursor = parentControl.PointToClient(ptCursor);
                CidContextMenu.Show(parentControl, ptCursor);                 // show on panel since events lost if on WebBrowser control

                while (CidContextMenu != null && CidContextMenu.Visible)      // keep this visible as long as popup is visible
                {
                    System.Threading.Thread.Sleep(250);
                    Application.DoEvents();
                }
            }

            else             // queue the command to execute after exiting this event
            {
                CommandToExecute = cmd;
                Timer_Tick(null, null);                 // just call directly for now, may need to fixup later to do after exiting the event
                //Timer.Start();
            }

            e.Cancel = true;             // we've taken care of it

            return(true);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Display the tool data
        /// </summary>
        /// <param name="qm"></param>
        /// <param name="serializeContentInQuery"></param>

        public static void DisplayDataOld(         // Old version from 1/4/2017
            QueryManager qm,
            MoleculeGridPanel gridPanel,
            bool serializeContentInQuery,
            bool fitDataToGridWidth = false)
        {
            MoleculeGridControl grid = null;

            bool displayAsNormalQueryResults = (gridPanel == null);                                  // if grid panel not defined assume display is in normal results panel
            bool displayAsPopupGrid          = (gridPanel != null && gridPanel.Parent is PopupGrid); // display in popup grid

            Query q = qm.Query;

            q.SetupQueryPagesAndViews();             // be sure we have a default view page

            if (serializeContentInQuery)
            {                                             // no database behind this table so persist within the query
                MetaTable mt = q.Tables[0].MetaTable;     // assume just one metatable
                foreach (MetaColumn mc in mt.MetaColumns) // no criteria allowed
                {
                    mc.IsSearchable = false;
                }

                q.SerializeMetaTablesWithQuery = true;             // if no broker then save the metatable definition
                q.SerializeResultsWithQuery    = true;             // also save results when saving the query
                q.BrowseSavedResultsUponOpen   = true;             // open the results when the query is opened
                q.ResultsDataTable             = qm.DataTable;     // point the query to this results table
            }

            ResultsFormatFactory rff = new ResultsFormatFactory(qm, OutputDest.WinForms);

            rff.Build();                                      // build format
            ResultsFormatter fmtr = new ResultsFormatter(qm); // and formatter

            if (displayAsNormalQueryResults)
            {
                gridPanel = SessionManager.Instance.QueryResultsControl.MoleculeGridPageControl.MoleculeGridPanel;
                QbUtil.AddQuery(qm.Query);                             // add to the list of visible queries
                QueriesControl.Instance.CurrentBrowseQuery = qm.Query; // make it current
            }

            grid = gridPanel.SelectBaseGridViewGrid(qm);

            //if (qm.ResultsFormat.UseBandedGridView)
            //	grid = gridPanel.BandedViewGrid;

            //else grid = gridPanel.LayoutViewGrid;

            qm.MoleculeGrid   = grid;
            grid.QueryManager = qm;

            DataTableMx dt = qm.DataTable;      // save ref to data table

            grid.DataSource = null;             // clear source for header build
            if (fitDataToGridWidth && grid.BGV != null)
            {
                grid.BGV.OptionsView.ColumnAutoWidth = true;                                                     // set view for auto width to fit within view
            }
            grid.FormatGridHeaders(qm.ResultsFormat);
            qm.DataTable = dt;                                 // restore data table

            qm.DataTableManager.SetResultsKeysFromDatatable(); // set the results keys

            if (displayAsNormalQueryResults)
            {
                QbUtil.SetMode(QueryMode.Browse);                 // put into browse mode
            }
            else if (displayAsPopupGrid)
            {
                PopupGrid pug = gridPanel.Parent as PopupGrid;
                pug.Initialize(qm);                 // be sure popup is initialized
                pug.Show();
            }

            gridPanel.Visible = true;
            grid.Visible      = true;
            grid.DataSource   = qm.DataTable;           // set the datasource for the grid to the datatable

            RefreshDataDisplay(qm);

            return;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Update the match counts panel and structure view based on a set of structures and filter values
        /// </summary>
        /// <param name="excludeCurrentHitList"></param>
        /// <param name="rssrs"></param>

        public void DisplayRelatedStructures(
            List <StructSearchMatch> fml)
        {
            MoleculeMx cs;

            if (fml == null || fml.Count == 0)
            {
                DisplayEmptyStructureGrid();
                return;
            }

            if (StructureDisplayQuery == null)
            {
                BuildStructureDisplayQuery();                                            // initial setup
            }
            Query               q    = StructureDisplayQuery;
            QueryTable          qt   = q.Tables[0];
            DataTableMx         dt   = Qm.DataTable;
            MoleculeGridControl grid = Qm.MoleculeGrid;

            grid.BeginUpdate();

            dt.Clear();             // filter table

            HashSet <string> cidSet = new HashSet <string>();

            for (int mi = 0; mi < fml.Count; mi++)             // build and add the rows to the datatable of structures
            {
                StructSearchMatch ssm = fml[mi];
                DataRowMx         dr  = dt.NewRow();
                dr[qt.Alias + ".CompoundId"] = ssm.SrcCid;

                cs = new MoleculeMx(ssm.MolStringFormat, ssm.MolString);
                if (Lex.IsDefined(ssm.SrcCid))
                {
                    cs.SetMolComments("CorpId=" + ssm.SrcCid);                    // Attach CorpId to Molfile so it will be rendered correctly
                }
                if (ssm.SearchType == StructureSearchType.SmallWorld && Lex.IsDefined(ssm.GraphicsString))
                {
                    cs.SvgString = ssm.GraphicsString;
                }

                dr[qt.Alias + ".Structure"]  = cs;
                dr[qt.Alias + ".MatchType"]  = ssm.SearchTypeName;
                dr[qt.Alias + ".MatchScore"] = ssm.MatchScore;
                dr[qt.Alias + ".Database"]   = ssm.SrcName;
                dt.Rows.Add(dr);

                cidSet.Add(ssm.SrcCid);
            }

            Qm.DataTableManager.InitializeRowAttributes();

            string title = "Related Structures - Matches: " + fml.Count + ", Compound Ids: " + cidSet.Count;

            Qm.MoleculeGrid.SetTableHeaderCaption(0, title);

            if (!RSC.MoleculeGridPageControl.Visible)
            {
                RSC.MoleculeGridPageControl.Visible = true;
            }

            grid.EndUpdate();
            ToolHelper.RefreshDataDisplay(Qm);

            return;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Link in QueryManager member
        /// </summary>
        /// <param name="m"></param>

        public void LinkMember(MoleculeGridControl m)
        {
            MoleculeGrid   = m;
            m.QueryManager = this;
        }
Exemplo n.º 16
0
/// <summary>
/// Setup & show the dialog
/// </summary>
/// <param name="queryManager"></param>
/// <param name="control"></param>
/// <returns></returns>

        public new static DialogResult Show(
            QueryManager queryManager,
            IPrintable control)
        {
// When the GridView is active we can mostly the standard DevExpress printing stuff.
// We just remove the Checkmark boxes and make sure all data is read in before starting the print.
// However, when LayoutView is active (Cids & structures only) we must work around a couple of issues.
// 1. Use CardView instead of LayoutView because LayoutView cards get split between pages.
// 2. Scaling does not put the proper number of cards per row. Fix by scaling the cards rather
//    than the print Document.
//
// Print scaling is persisted in Query.PrintScale

            if (Instance == null)
            {
                Instance = new PrintPreviewDialog();
            }
            Instance.Qm = queryManager;
            Query query = queryManager.Query;

            Instance.Control = control;

            if (control is MoleculeGridControl)
            {
                int    printScalePct = query.PrintScale;              // scale the document
                double scale         = printScalePct / 100.0;
                queryManager.ResultsFormat.PageScale = printScalePct; // do view scaling based on printScale

                MoleculeGridControl grid = control as MoleculeGridControl;
                ResultsFormat       rf   = queryManager.ResultsFormat;
                queryManager.DataTableManager.ResetFormattedBitmaps(); // for structures to be redrawn in correct size

                if (rf.UseBandedGridView)                              // hide check mark band for printing
                {
                    BandedGridView bgv = grid.MainView as BandedGridView;
                    if (Lex.Eq(bgv.Bands[0].Name, "CheckMark"))                     // hide checkmark band
                    {
                        bgv.Bands[0].Visible = false;
                    }

                    if (printScalePct > 0)
                    {
                        grid.ScaleBandedGridView(scale);                                        // scale the BandedGridView
                    }
                }

                else                 // switch to special card view for printing
                {
                    CardView cv = grid.GetCardView();
                    grid.MainView = cv;
                    string keyLabel = queryManager.Query.Tables[0].MetaTable.KeyMetaColumn.Label;
                    cv.CardCaptionFormat = keyLabel + ": {2}";                     // set proper caption

                    if (printScalePct > 0)
                    {
                        grid.ScaleCardView(scale);                                        // scale the CardView
                    }
                }

                DialogResult dr = ShowDialog(grid);

                // Reset the grid view

                queryManager.DataTableManager.ResetFormattedBitmaps();  // clear struct bitmaps so they get redrawn in correct size
                queryManager.ResultsFormat.PageScale = query.ViewScale; // switch back to doing view scaling based on viewScale

                if (rf.UseBandedGridView)                               // unhide check mark band
                {
                    BandedGridView bgv = grid.MainView as BandedGridView;
                    bgv.Bands[0].Visible = true;
                    grid.ScaleBandedGridView(query.ViewScale / 100.0);                     // scale back for viewing
                }

                else                 // switch back to layout view
                {
                    grid.MainView = grid.GetLayoutView();
                }

                grid.Refresh();

                return(dr);
            }

            else if (control is PivotGridControlMx)
            {
                PivotGridControlMx grid = control as PivotGridControlMx;
                DialogResult       dr   = ShowDialog(grid);
                return(dr);
            }

            //else if (control is ChartControlMx)
            //{
            //	ChartControlMx chart = control as ChartControlMx;
            //	DialogResult dr = ShowDialog(chart);
            //	return dr;
            //}

            else
            {
                throw new Exception("Invalid control type: " + control.GetType());
            }
        }