code

Thursday, 2 November 2017

Building x86 Wine on Mint x64

The following will get you a simple build of Wine on x64 version of Mint:

git clone git://source.winehq.org/git/wine.git                                                         
cd wine/                                                                                               
sudo apt-get install ia32-libs
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
sudo apt-get install gcc-multilib g++-multilib
sudo apt-get install xserver-xorg-dev:i386 libfreetype6-dev:i386
./configure
make
sudo make install

Tuesday, 31 October 2017

VirtualBox BSOD on Windows 10

See https://www.virtualbox.org/ticket/16801 as to what the issue is.

To turn off Windows 'Hyper-V' open the 'Windows Features' dialog.


Turn off 'Hyper-V' and reboot. Wish Virtual Box would warn me rather than crashing Windows.



Tuesday, 10 October 2017

Visual Studio "Find & Replace" Regular Expressions

I don't use regular expressions much in any code as I don't normally have any need for them.

However transforming code regular expressions come in handy.

The trick is remebering how to use regular expressions or to create a crib sheet

This one uses 'capture groups'.

Find:
(SID.*):

Replace With:
$1: return "$1";

Converts the following:

case  SID_AAAA:
case  SID_BBBBB:
case  SID_CCCCCC:

into:

case  SID_AAAA: return "SID_AAAA";
case  SID_BBBBB: return "SID_BBBBB";
case  SID_CCCCCC: return "SID_CCCCCC";



Sunday, 24 September 2017

Creating an RGB DIB rather than BGR DIB

Windows is normally BGR rather than RGB.

There is however away of creating a HBITMAP backed by a DIB which is RGB.

The trick is to use the following extra settings:

    bmi->bmiHeader.biCompression = BI_BITFIELDS;
    bmi->bmiColors[0].rgbBlue = 0xff;
    bmi->bmiColors[1].rgbGreen = 0xff;
    bmi->bmiColors[2].rgbRed = 0xff;

Everything else is kept the same.

This means that you no longer need to swap Red and Blue or tell OpenGL that you are passing BGR.


NOTE: The structure BITMAPINFO only contains one RGBQUAD so you need to create a BITMAPINFO  plus two extra RGBQUADs.

Thursday, 21 September 2017

Use of GIT (my crib sheet)

This is really a crib sheet for my-self.

Current file/folder status
  • git status
Get changes from remote branch (fetch and then merge):
  • git pull origin branch
  • git fetch origin branch
  • git merge origin branch
Get changes from all tracked branches
  • git pull
Storing changes 
  • git stash
  • git stash list
  • git stash apply
Push all changes from master to branch
  • git push origin master:branch
Create branch and switch to it.
  • git checkout -b branch
Switch to branch
  • git checkout branch
Merge changes from branch
  • git merge branch
Push my local changes to my remote branch
  • git push origin branch
Pull changes from the remote branch
  • git pull origin branch
Where branch is the name of the branch (locally or remote).


To clone a remote repository locally:
  • git clone git@gitlab.com:company/project.git
You can get the URL to use from the web interface.

After moving files use the following:
  •  git add -A .
Obtaining all branches:

  • git fetch --all
  • git fetch --prune
This will not update the local branches.

  • git pull -all

will update all local branches that are tracking remote branches

See all branches that are known about:
  • git branch --all
References:

Ignore changes to a file:

  • git update-index --assume-unchanged path_to_file
This is commonly used for application configuration files which have a set of defaults you don't want to checkin accidentally.

To undo use:
  • git update-index --no-assume-unchanged
To find all files that you have marked as not changed:
  • git ls-files -v | grep -E "^[a-z]"

Public/Private key generation:

  • ssh-keygen

Setting up SourceTree with gitlab.

Setup your public/private key locally using git (git-bash on Windows) and gitlab.
Clone the repository using the command line.
Use SourceTree with the local repository and use the command line to push/pull with remote repository.

Workflows

The following post 'A successful git branching model' is a good read.

The following branching scenario's probably have issues however they are the two I currently have to work with.

Staging Branch Workflow

Work in a local branch "mybranch".
Commit locally : $ git commit
Push changes to my remote branch: $ git push origin mybranch
Update your local branch from the remote staging branch: git pull origin staging
Fix the problems : git mergetool
Commit the changes: git commit
Push the changes to staging and my remote branch: $ git push origin mybranch:staging

The master branch is then updated from the staging branch. This means that access to master is stable and controlled.

Alternative Staging Branch Workflow (current approach)

1) $ git fetch --prune
2) Get your branch code working as you want, with changes committed to "mybranch"
3) Get the changes from staging: $ git pull origin staging
3a) Fix any issues and push back to "mybranch". This should make the merge with staging simpler.
4) Checkout staging: $ git checkout -B staging origin/staging
5) Merge your branch into staging:  git merge mybranch
6) Fix any conflicts: git mergetool
7) Commit changes: git commit
8) Push staging: git push origin staging
9) Switch back to mybranch: $ git checkout mybranch
10) Pull any changes back from staging: $ git pull origin staging

I can't help but think that this is more complex than it needs to be.

Diff/Merge Tools:

List of Merge/Diff tools on Windows.

The tool I am using is P4Merge.

Check that list of tools supports your tool and configure.
  • git mergetool --tool-help
  • git config --global merge.tool p4merge
  • git config --global mergetool.p4merge.path 'C:\Program Files\Perforce\p4merge.exe'
If your tool is not supported life is a lot more difficult:
  • git config --global mergetool.p4merge.cmd 'p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'
The tool will need to be in your path.

Note: occasionally you lose the combined view. The only way of restoring this is to delete the preferences file under AppData.

Visual Studio Advice

Learn the command line. You can not do everything in Visual Studio and some development shops don't allow you to install extensions into Visual Studio.

Advice On File Changes

If you are using Visual Studio merging changes with to Visual Studio projects is a nightmare. Try and avoid large changes to such files or consider using CMake to define what you are building and generate the project files.

Saturday, 16 September 2017

MapServer OpenLayers Example.

The following is a simple example of using OpenLayers with a MapServer WMS.

It is based on the OpenLayers examples.

<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="ol.css" type="text/css">
    <style>
      .map {
        height: 600px;
        width: 100%;
      }
    </style>
    <script src="ol.js" type="text/javascript"></script>
    <title>OpenLayers (4.3.2) MapServer WMS - Wales Imagery Example</title>
  </head>
  <body>
    <h2>OpenLayers (4.3.2) MapServer WMS - Wales Imagery Example</h2>
    <div id="map" class="map"></div>
<div id="mouse-position"></div>
    <form>
      <label>Projection </label>
      <select id="projection">
        <option value="EPSG:4326">EPSG:4326</option>
      </select>
      <label>Precision </label>
      <input id="precision" type="number" min="0" max="12" value="4"/>
    </form>
    <script type="text/javascript">
      var mousePositionControl = new ol.control.MousePosition({
        coordinateFormat: ol.coordinate.createStringXY(4),
        projection: 'EPSG:4326',
        // comment the following two lines to have the mouse position
        // be placed within the map.
        className: 'custom-mouse-position',
        target: document.getElementById('mouse-position'),
        undefinedHTML: '&nbsp;'
      });
  
      var map = new ol.Map({
    controls: ol.control.defaults({
          attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
               collapsible: false
          })
        }).extend([mousePositionControl]),
        layers: [
  new ol.layer.Tile({
            source: new ol.source.TileWMS({
      // MapServer URL this must be the same as the one declared in the
                      // MapServer .map file.
                          url : 'http://mapserver:8080/cgi-bin/mapserv.exe?map=wales_imagery.map',
  params : {
                                 // This must be the layer name as defined in the capabilities document
         'LAYERS' : 'wales_imagery',  
  'TILED': true,
'FORMAT': 'image/png',
'TRANSPARENT': 'true',
serverType: 'mapserver',
crossOrigin: 'anonymous'
  },
  projection : 'EPSG:4326',
  wrapX : false
}),
//opacity: 0.5
          })
        ],
        target: 'map',
        view: new ol.View({
          center: ol.proj.fromLonLat([-4.0, 51.7]),   // initial view position
          zoom: 9  // larger more zoomed in
        })
      });
  
      var projectionSelect = document.getElementById('projection');
      projectionSelect.addEventListener('change', function(event) {
        mousePositionControl.setProjection(event.target.value);
      });

      var precisionInput = document.getElementById('precision');
      precisionInput.addEventListener('change', function(event) {
        var format = ol.coordinate.createStringXY(event.target.valueAsNumber);
        mousePositionControl.setCoordinateFormat(format);
      });  
    </script>
  </body>
</html>


The bits in bold are what need to be configured correctly.

You can find out what layers are supported by a WMS Server using the GetCapabilities command:

http://127.0.0.1:8080/cgi-bin/mapserv.exe?map=wales_imagery.map&SERVICE=WMS&REQUEST=GetCapabilities

Make sure the ip address and port are correct.

What you are looking for is:

<Layer>
<Name>wales_imagery</Name>
<Title>WMS Server</Title>
<Abstract>This server was setup by damian.dixon at gmail.com</Abstract>
<CRS>EPSG:4326</CRS>

I was the Team Leader for MapLink Pro. Neil Tippett wrote a large part of the MapLink WMS Server. I ported the WMS server to Solaris and Linux and implemented the Xlib rendering and fine tuned it to run on multiple threads.